Adding multihost - locking

Adding Unit-Tests for it
This commit is contained in:
Philipp Holzer 2018-07-04 23:37:22 +02:00
parent b07dfbb03f
commit aac94d1d74
No known key found for this signature in database
GPG key ID: 58160D7D6AF942B6
22 changed files with 741 additions and 154 deletions

View file

@ -10,10 +10,13 @@ use Friendica\Core\Cache;
*
* @author Hypolite Petovan <mrpetovan@gmail.com>
*/
class MemcacheCacheDriver extends BaseObject implements ICacheDriver
class MemcacheCacheDriver extends BaseObject implements IMemoryCacheDriver
{
use TraitCompareSet;
use TraitCompareDelete;
/**
* @var Memcache
* @var \Memcache
*/
private $memcache;
@ -30,6 +33,9 @@ class MemcacheCacheDriver extends BaseObject implements ICacheDriver
}
}
/**
* (@inheritdoc)
*/
public function get($key)
{
$return = null;
@ -54,17 +60,31 @@ class MemcacheCacheDriver extends BaseObject implements ICacheDriver
return $return;
}
public function set($key, $value, $duration = Cache::MONTH)
/**
* (@inheritdoc)
*/
public function set($key, $value, $ttl = Cache::FIVE_MINUTES)
{
// We store with the hostname as key to avoid problems with other applications
return $this->memcache->set(
self::getApp()->get_hostname() . ":" . $key,
serialize($value),
MEMCACHE_COMPRESSED,
time() + $duration
);
if ($ttl > 0) {
return $this->memcache->set(
self::getApp()->get_hostname() . ":" . $key,
serialize($value),
MEMCACHE_COMPRESSED,
time() + $ttl
);
} else {
return $this->memcache->set(
self::getApp()->get_hostname() . ":" . $key,
serialize($value),
MEMCACHE_COMPRESSED
);
}
}
/**
* (@inheritdoc)
*/
public function delete($key)
{
return $this->memcache->delete($key);
@ -72,6 +92,14 @@ class MemcacheCacheDriver extends BaseObject implements ICacheDriver
public function clear()
{
return true;
return $this->memcache->flush();
}
/**
* (@inheritdoc)
*/
public function add($key, $value, $ttl = Cache::FIVE_MINUTES)
{
return $this->memcache->add(self::getApp()->get_hostname() . ":" . $key, $value, $ttl);
}
}