klenwell information services : PhpPearCacheLite

PEAR Cache Lite

return to DevPhp

Usage

# 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

Download (pear.php.net)
Documentation (pear.php.net)
Cache_Lite Class API (pear.php.net)
Set (or Get) Options (pear.php.net)
Phpwell Tests (code.google.com)