Easy Cache
Categories
Component ID
2846077
Component name
Easy Cache
Component type
module
Maintenance status
Development status
Component security advisory coverage
not-covered
Component created
Component changed
Component body
Makes it easy to cache any callback's result using an autogenerated cache key.
Usage:
function cachedCallback($arg1, $arg2) {
// Check cache
$cid = NULL; // we can use any cache id we want, or auto-generated
$result = module_exists('easy_cache') ? easy_cache_get($cid) : FALSE;
// If nothing there (NB can't distinguish a cached value of FALSE)
if ($result === FALSE) {
// Do complex calculations here
// ... $result can be any type
$result = array(1,2,3,4,5);
if (module_exists('easy_cache')) {
easy_cache_set($cid, $result);
}
}
return $result;
}
Helper functions autogenerate (and set by reference) the $cid argument if NULL, using a hash of the name of the parent callback using backtrace ('cachedCallback' above) and the serialized arguments (serialized value of array($arg1,$arg2) above). Optionally, a $cid can be specified.
Cache duration can be also be specified as the third argument to easy_cache_set().
Easy Cache tables are cleared on cron if expired.
