klenwell information services : PhpPearCacheLite

Wiki source for PhpPearCacheLite


Show raw source

=====PEAR Cache Lite=====
return to DevPhp

====Usage====
%%(php)
# import
require_once "Cache/Lite.php";

# config and instantiate
$cache_config = array(
'cacheDir' => '/tmp/',
'lifeTime' => 300,
'automaticCleaningFactor' => 200
);
$Cache = new Cache_Lite($cache_config);

# change a config
$Cache->setOption('automaticSerialization', TRUE);

# get a config (workaround)
$auto_serialize = $Cache->_automaticSerialization;
assert($auto_serialize);

# save cache
$cache_id = 'your cache key';
$payload = 'a string or, with automaticSerialization enabled, mixed value';
$cached = $Cache->save($payload, $cache_id);
assert($cached);

# retrieve cache
$retrieved = $Cache->get($cache_id);
assert($retrieved == $payload);

# clean cache
$removed = $Cache->remove($cache_id);
$retrieved = $Cache->get($cache_id);
assert(! $retrieved);
%%

====References====
[[http://pear.php.net/package/Cache_Lite/download | Download]] (pear.php.net)
[[http://pear.php.net/manual/en/package.caching.cache-lite.intro.php | Documentation]] (pear.php.net)
[[http://pear.php.net/package/Cache_Lite/docs/latest/apidoc/Cache_Lite/Cache_Lite.html | Cache_Lite Class API]] (pear.php.net)
[[http://pear.php.net/package/Cache_Lite/docs/latest/__filesource/fsource_Cache_Lite__Cache_Lite-1.7.8Lite.php.html#a296 | Set (or Get) Options]] (pear.php.net)
[[http://code.google.com/p/klenwell/source/browse/trunk/projects/php/phpwell/test/vendor/pear-cache_lite.php | Phpwell Tests]] (code.google.com)