We have to publish a daily index for regional markets on a block. There is a form to enter the data in a mysql table. The module is supposed to load the latest index by date. We have a function that reads the data and displays it on a block. The problem is that after the new data is inserted it does not show immediately. It takes a long time for the change to be reflected which is probably due to caching.

We have two modules. One has a from to capture the new data and save it to the database. The other module reads the latest data and displays it on a block on the front page (at the top of the page).

What is the best way to refresh the data within seconds or minutes? Block Refresh is nice but it is for 5.x.

Regards

Comments

tryitonce’s picture

Did you configure the performance settings in Drupal - ..../admin/settings/performance?

Good luck .....

aliegeh’s picture

Yes.

Caching Mode: Normal
Minimum Cache Lifetime: 1 min
Page Compression: Disabled
Block Cache: enabled
Optimize CSS Files: Enabled
Optimize javascrip files: Enabled

I want the entered data in a mysql table to refresh and overwrite yesterday's data with today's data once the role entering the data saves the record to the database. This is done in a form with a submit button. Is there a way to include the refresh after the submit. Does this involve js. The block is for

Here is the function for the block:

<?php
//$Id$
/**
* @file* Display AMDB Indexes.
*
*/

function amdbblock_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]["info"] = t('amdbblock');
$blocks[0]['cache'] = BLOCK_CACHE_GLOBAL;
return $blocks;
}
else if ($op == 'view') {
$result = get_index(1);
while($data=db_fetch_object($result)){
$indexdate = $data->Index_Date;
$year = substr($indexdate,0,4);
$month = substr($indexdate,4,2);
$day = substr($indexdate,6,2);
$indexdate = $day . '/' . $month . '/' . $year;
$indexvalue = $data->Index_Value;
$indexchange = $data->Index_Change;
$indexdirection = $data->Index_Direction;
}
$botlink = 'http://www.arabmonetaryfund.org/sites/default/files/econ/amdb/AMDB%20Ind...';
$toplink = 'http://www.arabmonetaryfund.org/sites/default/files/econ/amdb/AMDB%20Per...';
$indexstyle = 'amdb';

if ($indexdirection==0) {
$changestyle = 'changeup';
$datestyle = 'dateup';
$arrow = 'Only local images are allowed.';
}
else if ($indexdirection>0) {
$changestyle = 'changedown';
$datestyle = 'datedown';
$arrow = 'Only local images are allowed.';
}
$arrowstyle = 'arrow';
$blocks['content'] = '' .
'

' . '

' .
'' .
'
' . $indexdate . '

' .
'

' . $indexchange . '

' .
'

' . $arrow . '

' . '

';
return $blocks;
}
}
------------------------------------------------------------

Here is the the data entry form:

function amdbindex_entry_form_submit($form, $form_state) {
$year = $form_state['values']['Index_Date']['year'];
$month = $form_state['values']['Index_Date']['month'];
$day = $form_state['values']['Index_Date']['day'];
$day = str_pad($day, 2, 0, STR_PAD_LEFT);
$indexdate = $year . $month . $day;

/* $indexdate = $form_state['values']['Index_Date']['year'] . '-' . $form_state['values']['Index_Date']['month'] . '-' . $form_state['values']['Index_Date']['day']; */
//$indexdate = $form_state['values']['Index_Date']['year'] . $form_state['values']['Index_Date']['month'] . $form_state['values']['Index_Date']['day'];
$indexvalue = $form_state['values']['Index_Value'];
$indexchange = $form_state['values']['Index_Change'];
$indexdirection = $form_state['values']['Index_Direction'];
/* db_query('DELETE FROM {amdb_index} WHERE Index_Date = %d',
$indexdate); */
$data = array(
'Index_Date' => $indexdate,
'Index_Value' => $indexvalue,
'Index_Change' => $indexchange,
'Index_Direction' => $indexdirection
);
$is_existing = db_result(db_query("SELECT COUNT(*) FROM {amdb_index} WHERE index_date = '%s'", $indexdate));
if ($is_existing == 0 ) {
drupal_write_record('amdb_index',$data);
}
else if ($is_existing > 0 ) {
drupal_write_record('amdb_index',$data,'Index_Date');
}
cache_clear_all('amdbblock','cache');
amdbblock_block('view',0);
drupal_set_message(t('Your Index Value has been saved.'));
}

Regards

bscott’s picture

Change BLOCK_CACHE_GLOBAL to BLOCK_NO_CACHE ?

aliegeh’s picture

Thanks. Already did but that did not help either. The block refreshes after hours in both cases.

bscott’s picture

What happens if you disable Drupal's caching?

aliegeh’s picture

After disabling caching as you suggested, the block gets refreshed immediately.

But this does not resolve the issue as caching is important for improving the performance of the site.

Regards

tryitonce’s picture

The idea - I guess - is that caching is enabled for a working site.

Adding data directly to MySQL db is more likely a thing during development or maintenance - thus for those times you might have to go into development / maintenance mode and turn off caching manually and reset it after the job is done. Some things can be automated - but not all tasks.

Good luck ... and a happy NY 2010

aliegeh’s picture

Happy New year.

The module, block refresh, is a good module for refreshing new data captured into mysql. It is a very good solution for our purpose but the problem is that it is for 5.x. I guess we will try to use the same concept. This involves using ajax.

Regards

bscott’s picture

I was trying to establish if your problem was within Drupal or somewhere else. I understand that you would not want to disable caching on your live site.