Updated - 26/03/2008 - Download - Khaos::KhCache-0.3
Introduction
KhCache is a pretty basic caching library currently with two containers (File and APC), the library is designed to complement codeigniters own caching system by allowing you to cache the output of smaller segments of code when no full page cache is available for CI to directly display.
Quick Reference
/*
* KhCache
*
* mixed fetch ( string $key)
* bool store ( string $key, mixed $data [, int $ttl] )
* mixed call ( callback $func [, array $args [, int $ttl ]] )
* bool delete ( string $key )
* bool delete_all ( )
* string generatekey ( mixed $arg1 [, mixed $arg2 [, mixed $... ]] )
* int get_hits ( )
* int get_misses ( )
*/
// Example General Usage
if (($data = $this->khcache->fetch('test')) === false)
{
/*
* Resource intensive code here which places data to be
* cached within the $data variable.
*/
// Save Cache
$this->khcache->store('test', $data);
}
// Example Function Caching
$data = $this->khcache->call('transform_xsl', array($xsl, $xml));
Configuration
KhCache will work right out the box aslong as the system/cache folder is writable. However if you wish to change the behaviour of KhCache then create the config file khaos.php.
Below is a sample config which represents the default behaviour of KhCache.
$config['cache'] = array('container' => 'File',
'ttl' => 3600,
'File' => array('store' => BASEPATH.'cache/',
'auto_clean' => 10,
'auto_clean_life' => 3600,
'auto_clean_all' => false));
everything in the config file is optional so options only need to be specified if you wish to override the default behaviour. for example if you wished to use APC then the config would simply be
$config['cache'] = array('container' => 'APC');
auto_clean - By default there is a 1 in 10 chance of the cache dir being cleaned, set to false to disable.
auto_clean_life - Files older than this will be removed.
auto_clean_all - By default only cache files prefixed with khcache_ are removed set to true to have khcache clean the entire directory
