Every repository with this icon (
Every repository with this icon (
tree 1e3aa1923c78f5753b19b196a763dc8a3d2c8320
parent e327bdcfe0ddd9a429837a266064ee846014b77e
pca - Pluggable Cache Architecture
Introduction
What is pca?
pca is an abstraction layer for various caches like memcached. It provides a common basic set of operations and makes sure the results are uniform across the various backends. pca uses SimpleTest for unit tests.
Supported backends
- Alternative PHP Cache
- Filesystem backend (with checksumming to avoid cache corruption)
- Memcached
- PDO: mySQL, Postgres, sqlite, ... (see PDO drivers)
License
pca is released into the public domain, see LICENSE.
Using pca
Loading a backend
For a full list of backends and their configuration options please take a look at the API documentation. For example, to use the memcached backend, you can use this code:
require_once('path/to/pca_dir/pca/pca.class.php');
$options = array('server' => array('host' => 'localhost'));
$cache = PCA::factory('memcache', $options);
You can also let pca guess the best possible cache backend to avoid confusing the users of your software with a shitload of configuration options:
require_once('path/to/pca_dir/pca/pca.class.php');
$cache = PCA::get_best_backend();
Storing, retrieving and manipulating values
Store a value for 1 hour:
$cache->set('foo', 'bar', 3600)
Check if a value exists:
if($cache->exists('foo'))
echo 'Found "foo"';
else
echo 'No "foo" for you';
Retrieve the value (returns null when the value is empty):
$cache->get('foo');
Add a value only if it does not exist yet:
if($cache->add('foo', 'new_bar'))
echo 'Key "foo" did not exist yet, created it';
else
echo 'Don\'t mess with the "foo"';
Delete a value:
$cache->delete('foo');
Other operations
Delete all cached data:
$cache->flush();
The Filesystem and PDO backends require garbage collection to delete values that have expired, so make sure that you periodically run it:
$cache->gc();







