public
Description: A PHP5 cache abstraction layer supporting APC, database, filesystem and memcached
Homepage: http://soultcer.net/wiki/Code/pca
Clone URL: git://github.com/soult/pca.git
pca /
name age message
file .gitignore Loading commit data...
file Doxyfile
file LICENSE
file README.rst Fri Apr 10 18:18:11 -0700 2009 Add link to API documentation in README.rst [soult]
directory data/
directory pca/
directory tests/

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

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();