mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 03:23:19 +00:00
123 lines
2.1 KiB
PHP
123 lines
2.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2012 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Alchemy\Phrasea\Cache;
|
|
|
|
use Doctrine\Common\Cache\CacheProvider;
|
|
|
|
/**
|
|
*
|
|
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
|
* @link www.phraseanet.com
|
|
*/
|
|
class RedisCache extends CacheProvider
|
|
{
|
|
/**
|
|
* @var \Redis
|
|
*/
|
|
private $_redis;
|
|
|
|
/**
|
|
* Sets the redis instance to use.
|
|
*
|
|
* @param Redis $memcache
|
|
*/
|
|
public function setRedis(\Redis $redis)
|
|
{
|
|
$this->_redis = $redis;
|
|
}
|
|
|
|
/**
|
|
* Gets the memcache instance used by the cache.
|
|
*
|
|
* @return Memcache
|
|
*/
|
|
public function getRedis()
|
|
{
|
|
return $this->_redis;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function doFetch($id)
|
|
{
|
|
return $this->_redis->get($id);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function doContains($id)
|
|
{
|
|
return (bool) $this->_redis->get($id);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function doSave($id, $data, $lifeTime = 0)
|
|
{
|
|
if (0 === $lifeTime) {
|
|
return $this->_redis->set($id, $data);
|
|
} else {
|
|
return $this->_redis->setex($id, $lifeTime, $data);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function doDelete($id)
|
|
{
|
|
return $this->_redis->delete($id);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function doFlush()
|
|
{
|
|
return $this->_redis->flushAll();
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function doGetStats()
|
|
{
|
|
return $this->_redis->info();
|
|
}
|
|
|
|
public function isServer()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function get($key)
|
|
{
|
|
if ( ! $this->contains($key)) {
|
|
throw new Exception('Unable to retrieve the value');
|
|
}
|
|
|
|
return $this->fetch($key);
|
|
}
|
|
|
|
public function deleteMulti(array $array_keys)
|
|
{
|
|
foreach ($array_keys as $id) {
|
|
$this->delete($id);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|