use Friendica\Core\Cache;
+use Exception;
+use Memcache;
+
/**
* Memcache Cache Driver
*
- * @author Hypolite Petovan <mrpetovan@gmail.com>
+ * @author Hypolite Petovan <hypolite@mrpetovan.com>
*/
class MemcacheCacheDriver extends AbstractCacheDriver implements IMemoryCacheDriver
{
use TraitCompareDelete;
/**
- * @var \Memcache
+ * @var Memcache
*/
private $memcache;
public function __construct($memcache_host, $memcache_port)
{
if (!class_exists('Memcache', false)) {
- throw new \Exception('Memcache class isn\'t available');
+ throw new Exception('Memcache class isn\'t available');
}
- $this->memcache = new \Memcache();
+ $this->memcache = new Memcache();
if (!$this->memcache->connect($memcache_host, $memcache_port)) {
- throw new \Exception('Expected Memcache server at ' . $memcache_host . ':' . $memcache_port . ' isn\'t available');
+ throw new Exception('Expected Memcache server at ' . $memcache_host . ':' . $memcache_port . ' isn\'t available');
}
}
/**
* (@inheritdoc)
*/
- public function clear()
+ public function clear($outdated = true)
{
- return $this->memcache->flush();
+ if ($outdated) {
+ return true;
+ } else {
+ return $this->memcache->flush();
+ }
}
/**
public function add($key, $value, $ttl = Cache::FIVE_MINUTES)
{
$cachekey = $this->getCacheKey($key);
- return $this->memcache->add($cachekey, $value, $ttl);
+ return $this->memcache->add($cachekey, serialize($value), MEMCACHE_COMPRESSED, $ttl);
}
}