A simple static wrapper for Doctrine Cache drivers.
- PHP >= 5.3
- Doctrine Cache >= 1.5.1
Add a dependency on thefuriouscoder/doctrine-cache-factory
to your project's composer.json
file.
{
"require": {
"thefuriouscoder/doctrine-cache-factory": "dev-master"
}
}
Add the following configuration code to your project bootstraping file depending on the storage you are goinng to use.
// configure memcached setting.
TFC\Cache\DoctrineCacheFactory::setOption(
[
'storage' => 'memcached',
'prefix' => 'rlyeh',
'default_ttl' => 3600,
'servers' => [
['server1', 11211, 20],
['server2', 11211, 80]
]
]
);
// configure APC setting.
TFC\Cache\DoctrineCacheFactory::setOption(
[
'storage' => 'apc',
'default_ttl' => 3600
]
);
// configure Redis setting.
TFC\Cache\DoctrineCacheFactory::setOption(
[
'storage' => 'redis',
'prefix' => 'rlyeh',
'host => '127.0.0.1',
'port' => 6379,
'default_ttl' => 3600
]
);
$cache = \TFC\Cache\DoctrineCacheFactory::factory("redis");
$cache->setNamespace("miskatonic");
$cache->save($key,$data);
$cache->contains($key);
$data = $cache->fetch($key);
$cache->delete($key);
$cache->deleteAll();
For more detailed instructions on Doctrine cache usage, please refer to doctrine documentation
MIT License