mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-09 05:04:28 +02: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,8 +10,11 @@ use Friendica\Core\Cache;
|
|||
*
|
||||
* @author Hypolite Petovan <mrpetovan@gmail.com>
|
||||
*/
|
||||
class MemcachedCacheDriver extends BaseObject implements ICacheDriver
|
||||
class MemcachedCacheDriver extends BaseObject implements IMemoryCacheDriver
|
||||
{
|
||||
use TraitCompareSet;
|
||||
use TraitCompareDelete;
|
||||
|
||||
/**
|
||||
* @var Memcached
|
||||
*/
|
||||
|
@ -46,14 +49,22 @@ class MemcachedCacheDriver extends BaseObject implements ICacheDriver
|
|||
return $return;
|
||||
}
|
||||
|
||||
public function set($key, $value, $duration = Cache::MONTH)
|
||||
public function set($key, $value, $ttl = Cache::FIVE_MINUTES)
|
||||
{
|
||||
// We store with the hostname as key to avoid problems with other applications
|
||||
return $this->memcached->set(
|
||||
self::getApp()->get_hostname() . ':' . $key,
|
||||
$value,
|
||||
time() + $duration
|
||||
);
|
||||
if ($ttl > 0) {
|
||||
return $this->memcached->set(
|
||||
self::getApp()->get_hostname() . ':' . $key,
|
||||
$value,
|
||||
time() + $ttl
|
||||
);
|
||||
} else {
|
||||
return $this->memcached->set(
|
||||
self::getApp()->get_hostname() . ':' . $key,
|
||||
$value
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function delete($key)
|
||||
|
@ -67,4 +78,17 @@ class MemcachedCacheDriver extends BaseObject implements ICacheDriver
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a value if it's not already stored
|
||||
*
|
||||
* @param string $key The cache key
|
||||
* @param mixed $value The old value we know from the cache
|
||||
* @param int $ttl The cache lifespan, must be one of the Cache constants
|
||||
* @return bool
|
||||
*/
|
||||
public function add($key, $value, $ttl = Cache::FIVE_MINUTES)
|
||||
{
|
||||
return $this->memcached->add(self::getApp()->get_hostname() . ":" . $key, $value, $ttl);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue