It is frequent for the type of site I build (records label, clubs, bands) to have an event listing built with views that doesn't update because the cache is active and since new content and/or comments are inserted rarely the cache isn't flushed. Infact drupal doesn't rebuild the cache until content is created or modified and therefore a dynamic view that list (e.g. upcoming concerts) isn't updated. So it would be cool to have an option for a maximum cache lifetime.

Comments

kbahey’s picture

We don't need this to be in core.

You can do this via a small module, like this:

Create a file called cache_reset.info and put in it the following:

name = Cache Reset
description = Resets all caches periodically via cron
core = 7.x
package = Cache

Then create a file called cache_reset.module and put in it the following:


define('CACHE_RESET_INTERVAL', 3600);

function cache_reset_cron() {
  // Check if we should do the processing
  $last = variable_get('cache_reset_last', '');
  if (time() - $last < CACHE_RESET_INTERVAL) {
    return;
  }

  drupal_flush_all_caches();
  
  variable_set('cache_reset_last', time());

  watchdog('cache_reset', 'All caches have been reset');

This will reset the cache every hour.

dodorama’s picture

Thanks for the hint.
I was wondering if using cache_clear_all with drupal 5 is the same (drupal_flush_all_caches is not available).

sun’s picture

Status: Active » Closed (won't fix)

Flushing caches when cron runs would be insane.

kbahey’s picture

Status: Closed (won't fix) » Active

It is not insane.

If it is, then why do we have this code in system module in Drupal 6?

$core = array('cache', 'cache_block', 'cache_filter', 'cache_page', 'cache_form', 'cache_menu');
$cache_tables = array_merge(module_invoke_all('flush_caches'), $core);
foreach ($cache_tables as $table) {
  cache_clear_all(NULL, $table);
} 
sun’s picture

Because it only flushes _expired_ cache entries?