Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Consistent Cache Interface for PHP
PHP
tag: 1.0.6

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src/UniversalCache
tests
README.md
build.xml
composer.json
package.ini
package.xml
phpdox.xml
phprelease.ini
phpunit-ci.xml
phpunit.xml

README.md

UniversalCache

A Generic Cache Interface for PHP.

UniversalCache Interface

UniversalCache class provides an interface to operate on different cache backend, you may put the fastest cache backend to the first position, so that you can fetch the cache very quickly.

use UniversalCache;
$cache = new UniversalCache(array( 
new ApcCache(array( 'namespace' => 'app_' )),
new FileSystemCache(array( 'cache_dir' => ... ))
));
$cache->set('key', 'value');
$value = $cache->get('key');
$memory      = UniversalCache::create( 'MemoryCache' );
$memcache    = UniversalCache::create( 'MemcacheCache' );

$c = new UniversalCache(array($memory,$memcache));
$c->set( 'foo' , 123 );

$memory->set( 'foo' , '123' );
$val = $memory->get('foo');

$memcache->set('foo', '123' );
$memcache->get('foo', '123' );

ApcCache

$cache = new UniversalCache\ApcCache(array( 
    'namespace' => 'app_',
    'default_expiry' => 3600,
));
$cache->set($name,$val);
$val = $cache->get($name);
$cache->remove($name);

MemoryCache

$cache = new UniversalCache\MemoryCache;
$cache->set($name,$val);
$val = $cache->get($name);
$cache->remove($name);

MemcacheCache

$cache = new UniversalCache\MemcacheCache(array( 
    'servers' => [ ['localhost', 123123], ['server2',123123] ]
));
$cache->set($name,$val);
$val = $cache->get($name);
$cache->remove($name);

FileSystemCache

$serializer = new SerializerKit\Serializer('json');
$cache = new UniversalCache\FileSystemCache(array( 
    'expiry' => 30,
    'cache_dir' => 'cache',
    'serializer' => $serializer,
));
$cache->clear();

$url = 'foo_bar';
$html = 'test content';
$cache->set( $url , $html );

$cache->remove( $url );

ok( null === $cache->get( $url ) );

$cache->clear();

ok( null === $cache->get( $url ) );

Hacking

$ pear install -a -f corneltek/Universal
$ pear install -a -f corneltek/PHPUnit_TestMore
$ onion install
$ phpunit
Something went wrong with that request. Please try again.