cache_graceful-2.png
cache_graceful-1.png

Cache Graceful allows you to update cache in the background, without having to wait for it.

Available through API and a cache plugin for Views and Panels.

Dependencies

Supported modules

Developer

To cache e.g. a node for 20 seconds, you would usually do something like this:

<?php
  $nid
= 1;
 
$key = 'cache_node:' . $nid;
  if (
$cache = cache_get($key)) {
   
$node = $cache->data;
  }
  else {
   
$node = node_load($nid);
   
cache_set($key, $node, 'cache', time() + 20);
  }
?>

Cache Graceful allows you to update the cache in background, before it expires, in this example 10 seconds before.

<?php
  $nid
= 1;
 
$key = 'cache_node:' . $nid;
 
$node = cache_graceful($key, array('node_load', $nid), 'cache', 20, 10);
?>

Cache Graceful can also handle thundering herds, and will wait for the cache to be updated if an update is currently in progress.
The time to wait for the cache is configurable via settings.

Generel Caching

Cache Graceful can also be used as a caching backend.

To enable, add to settings.php:

Drupal 6

NOTE: Requires Cache Backport for cache.inc replacement.

<?php>
$conf['cache_backends'] = array(
 
'sites/all/modules/cache_graceful/cache_graceful.inc',
);

$conf['cache_inc'] = 'sites/all/modules/cache_backport/cache.inc';
$conf['cache_default_class'] = 'GracefulCache';
$conf['graceful_cache_default_class'] = 'DrupalDatabaseCache';
?>

Drupal 7

<?php
$conf
['cache_backends'] = array(
 
'sites/all/modules/cache_graceful/cache_graceful.inc',
);

$conf['cache_default_class'] = 'GracefulCache';
$conf['graceful_cache_default_class'] = 'DrupalDatabaseCache';

// Example: Use memcach for the menu cache
$conf['graceful_cache_class_cache_menu'] = 'MemCacheDrupal';
?>

Heuristic caching

You can mix and match caching backends, e.g. adding heuristic caching to the Drupal 7 example above using Cache Heuristic

<?php
$conf
['cache_backends'] = array(
 
'sites/all/modules/cache_graceful/cache_graceful.inc',
 
'sites/all/modules/cache_heuristic/cache_heuristic.inc',
);

$conf['cache_default_class'] = 'GracefulCache';
$conf['graceful_cache_default_class'] = 'HeuristicCache';
$conf['heuristic_cache_default_class'] = 'DrupalDatabaseCache';

// Example: Use memcach for the menu cache
$conf['heuristic_cache_class_cache_menu'] = 'MemCacheDrupal';
?>

Project Information

Downloads