mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Add cache provider for memcached extension
This commit is contained in:
@@ -45,6 +45,10 @@ class Factory
|
|||||||
case 'memcachecache':
|
case 'memcachecache':
|
||||||
$cache = $this->createMemcache($options);
|
$cache = $this->createMemcache($options);
|
||||||
break;
|
break;
|
||||||
|
case 'memcached':
|
||||||
|
case 'memcachecached':
|
||||||
|
$cache = $this->createMemcached($options);
|
||||||
|
break;
|
||||||
case 'redis':
|
case 'redis':
|
||||||
case 'rediscache':
|
case 'rediscache':
|
||||||
$cache = $this->createRedis($options);
|
$cache = $this->createRedis($options);
|
||||||
@@ -131,6 +135,29 @@ class Factory
|
|||||||
return $cache;
|
return $cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createMemcached($options)
|
||||||
|
{
|
||||||
|
if (!extension_loaded('memcached')) {
|
||||||
|
throw new RuntimeException('The Memcached cache requires the Memcached extension.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$host = isset($options['host']) ? $options['host'] : 'localhost';
|
||||||
|
$port = isset($options['port']) ? $options['port'] : 11211;
|
||||||
|
|
||||||
|
$memcached = new \Memcached();
|
||||||
|
$memcached->addServer($host, $port);
|
||||||
|
$memcached->getStats();
|
||||||
|
|
||||||
|
if (\Memcached::RES_SUCCESS !== $memcached->getResultCode()) {
|
||||||
|
throw new RuntimeException(sprintf("Memcached instance with host '%s' and port '%s' is not reachable", $host, $port));
|
||||||
|
}
|
||||||
|
|
||||||
|
$cache = new MemcachedCache();
|
||||||
|
$cache->setMemcached($memcached);
|
||||||
|
|
||||||
|
return $cache;
|
||||||
|
}
|
||||||
|
|
||||||
private function createApc($options)
|
private function createApc($options)
|
||||||
{
|
{
|
||||||
if (!extension_loaded('apc')) {
|
if (!extension_loaded('apc')) {
|
||||||
|
@@ -28,6 +28,8 @@ class FactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
array('arraycache', null, 'Alchemy\Phrasea\Cache\ArrayCache'),
|
array('arraycache', null, 'Alchemy\Phrasea\Cache\ArrayCache'),
|
||||||
array('memcache', 'memcache', 'Alchemy\Phrasea\Cache\MemcacheCache'),
|
array('memcache', 'memcache', 'Alchemy\Phrasea\Cache\MemcacheCache'),
|
||||||
array('memcachecache', 'memcache', 'Alchemy\Phrasea\Cache\MemcacheCache'),
|
array('memcachecache', 'memcache', 'Alchemy\Phrasea\Cache\MemcacheCache'),
|
||||||
|
array('memcached', 'memcached', 'Alchemy\Phrasea\Cache\MemcachedCache'),
|
||||||
|
array('memcachecached', 'memcached', 'Alchemy\Phrasea\Cache\MemcachedCache'),
|
||||||
array('redis', 'redis', 'Alchemy\Phrasea\Cache\RedisCache'),
|
array('redis', 'redis', 'Alchemy\Phrasea\Cache\RedisCache'),
|
||||||
array('rediscache', 'redis', 'Alchemy\Phrasea\Cache\RedisCache'),
|
array('rediscache', 'redis', 'Alchemy\Phrasea\Cache\RedisCache'),
|
||||||
array('wincache', 'wincache', 'Alchemy\Phrasea\Cache\WincacheCache'),
|
array('wincache', 'wincache', 'Alchemy\Phrasea\Cache\WincacheCache'),
|
||||||
|
Reference in New Issue
Block a user