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.
Dependencies
Developer
To cache e.g. a node for 20 seconds, you would usually do something like this:
$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.
$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
$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
$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
$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';Downloads
Recommended releases
Development releases
Project Information
- Maintenance status: Actively maintained
- Development status: Under active development
- Module categories: Developer, Performance and Scalability, Views
- Reported installs: 27 sites currently report using this module. View usage statistics.
- Downloads: 587
- Last modified: May 14, 2012

