mirror of
https://github.com/friendica/friendica
synced 2025-04-22 21:10:10 +00:00
Adding multihost - locking
Adding Unit-Tests for it
This commit is contained in:
parent
b07dfbb03f
commit
aac94d1d74
22 changed files with 741 additions and 154 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue