dev-master
9999999-devYet another caching implementation
dbad
The Requires
- php >=5.4.0
The Development Requires
by Boris Verhaaff
file cache redis memcache apc memcached mongo riak
Yet another caching implementation
Yet another caching implementation., (*1)
Basic usage applies to all cache storage options, (*3)
use Websoftwares\Cache, Websoftwares\Storage\File; $cache = Cache::storage(new File()); $cache->save('key',["a","b","c"]); // Retrieve the cache $cache->get('key');
Available storage options:, (*4)
use Websoftwares\Cache, Websoftwares\Storage\Apc; $apc = Cache::storage(new Apc()) ->setExpiration(86400); $apc->save('key',["a","b","c"]); // Retrieve the cache $apc->get('key');
use Websoftwares\Cache, Websoftwares\Storage\File; $cache = Cache::storage(new File()) ->setPath('/super/spot') ->setExpiration(86400); $cache->save('key',["a","b","c"]); // Retrieve the cache $cache->get('key');
This requires u have the PHP memcache extension installed., (*5)
on Debian/Ubuntu systems for example install like this (requires administrative password)., (*6)
sudo apt-get install php5-memcache
use Websoftwares\Cache, Websoftwares\Storage\Memcache; $memcache = Cache::storage(new Memcache()) ->setConnection(function() { $instance = new \Memcache; $instance->connect('localhost','11211'); return $instance; }) ->setExpiration(86400); $memcache->save('key',["a","b","c"]); // Retrieve the cache $memcache->get('key');
This requires u have the PHP memcached extension installed., (*7)
on Debian/Ubuntu systems for example install like this (requires administrative password)., (*8)
sudo apt-get install php5-memcached
use Websoftwares\Cache, Websoftwares\Storage\Memcached; $memcached = Cache::storage(new Memcached()) ->setConnection(function() { $instance = new \Memcached(); $instance->addServer("localhost", 11211); return $instance; }) ->setExpiration(86400); $memcached->save('key',["a","b","c"]); // Retrieve the cache $memcached->get('key');
This storage option makes use of the "ensureIndex" method option "expireAfterSeconds"., (*9)
This option can only be used if the following requirements are met., (*10)
Requirements: * Latest PHP Mongo extension installed * mongoDB deamon version 2.2+ | read more, (*11)
On debian/ubuntu systems run the following command to install the mongo extension (requires administrator password)., (*12)
sudo pecl install mongo
use Websoftwares\Cache, Websoftwares\Storage\Mongo; $mongo = Cache::storage(new Mongo()) ->setConnection(function() { $m = new \MongoClient(); $db = $m->mongocache; return $db; }) ->setCollection('test') ->setExpiration(86400); $mongo->save('key',["a","b","c"]); // Retrieve the cache $mongo->get('key');
This requires u have the PHP Predis package installed., (*13)
use Websoftwares\Cache, Websoftwares\Storage\Redis; $redis = Cache::storage(new Redis()) ->setConnection(function() { $client = new \Predis\Client([ 'scheme' => 'tcp', 'host' => '127.0.0.1', 'port' => 6379, ]); return $client; }) ->setExpiration(86400); $redis->save('key',["a","b","c"]); // Retrieve the cache $redis->get('key');
This requires u have the PHP Riak official package installed., (*14)
use Websoftwares\Cache, Websoftwares\Storage\Riak; $riak = Cache::storage(new Riak()) ->setConnection(function() { $client = new \Basho\Riak\Riak('127.0.0.1', 8098); return $client; }) ->setBucket('testBucket') ->setExpiration(86400); $riak->save('key',["a","b","c"]); // Retrieve the cache $riak->get('key');
Yet another caching implementation
dbad
file cache redis memcache apc memcached mongo riak