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
soult (author)
Fri Apr 10 18:18:11 -0700 2009
commit  96fef8d2170af042d05611a4eeea9e2c402b861d
tree    1e3aa1923c78f5753b19b196a763dc8a3d2c8320
parent  e327bdcfe0ddd9a429837a266064ee846014b77e
pca /
name age message
file .gitignore Loading commit data...
file Doxyfile
file LICENSE Mon Nov 03 07:12:07 -0800 2008 Add LICENSE (Public Domain) [soult]
file README.rst
directory data/ Thu Nov 06 14:42:44 -0800 2008 Add PDO (database) backend The PDOBackend uses... [soult]
directory pca/
directory tests/
README.rst

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