mirror of
https://github.com/friendica/friendica
synced 2025-04-26 17:50:11 +00:00
Added Unittests for cache
fixed Lock & Cache bugs
This commit is contained in:
parent
1dafaa69c5
commit
80a4e6263f
18 changed files with 317 additions and 25 deletions
|
@ -51,7 +51,7 @@ class ArrayCache extends AbstractCacheDriver implements IMemoryCacheDriver
|
|||
/**
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function clear()
|
||||
public function clear($outdated = true)
|
||||
{
|
||||
$this->cachedData = [];
|
||||
return true;
|
||||
|
|
|
@ -37,7 +37,7 @@ class DatabaseCacheDriver extends AbstractCacheDriver implements ICacheDriver
|
|||
{
|
||||
$fields = [
|
||||
'v' => serialize($value),
|
||||
'expires' => DateTimeFormat::utc('now + ' . $ttl . ' seconds'),
|
||||
'expires' => DateTimeFormat::utc('now + ' . $ttl . 'seconds'),
|
||||
'updated' => DateTimeFormat::utcNow()
|
||||
];
|
||||
|
||||
|
@ -49,8 +49,12 @@ class DatabaseCacheDriver extends AbstractCacheDriver implements ICacheDriver
|
|||
return dba::delete('cache', ['k' => $key]);
|
||||
}
|
||||
|
||||
public function clear()
|
||||
public function clear($outdated = true)
|
||||
{
|
||||
return dba::delete('cache', ['`expires` < NOW()']);
|
||||
if ($outdated) {
|
||||
return dba::delete('cache', ['`expires` < NOW()']);
|
||||
} else {
|
||||
return dba::delete('cache', ['`k` IS NOT NULL ']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,8 +42,9 @@ interface ICacheDriver
|
|||
|
||||
/**
|
||||
* Remove outdated data from the cache
|
||||
* @param boolean $outdated just remove outdated values
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clear();
|
||||
public function clear($outdated = true);
|
||||
}
|
||||
|
|
|
@ -96,9 +96,13 @@ class MemcacheCacheDriver extends AbstractCacheDriver implements IMemoryCacheDri
|
|||
/**
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
public function clear()
|
||||
public function clear($outdated = true)
|
||||
{
|
||||
return $this->memcache->flush();
|
||||
if ($outdated) {
|
||||
return true;
|
||||
} else {
|
||||
return $this->memcache->flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -58,7 +58,7 @@ class MemcachedCacheDriver extends AbstractCacheDriver implements IMemoryCacheDr
|
|||
return $this->memcached->set(
|
||||
$cachekey,
|
||||
$value,
|
||||
time() + $ttl
|
||||
$ttl
|
||||
);
|
||||
} else {
|
||||
return $this->memcached->set(
|
||||
|
@ -75,9 +75,13 @@ class MemcachedCacheDriver extends AbstractCacheDriver implements IMemoryCacheDr
|
|||
return $this->memcached->delete($cachekey);
|
||||
}
|
||||
|
||||
public function clear()
|
||||
public function clear($outdated = true)
|
||||
{
|
||||
return $this->memcached->flush();
|
||||
if ($outdated) {
|
||||
return true;
|
||||
} else {
|
||||
return $this->memcached->flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -61,7 +61,7 @@ class RedisCacheDriver extends AbstractCacheDriver implements IMemoryCacheDriver
|
|||
if ($ttl > 0) {
|
||||
return $this->redis->setex(
|
||||
$cachekey,
|
||||
time() + $ttl,
|
||||
$ttl,
|
||||
$cached
|
||||
);
|
||||
} else {
|
||||
|
@ -78,12 +78,15 @@ class RedisCacheDriver extends AbstractCacheDriver implements IMemoryCacheDriver
|
|||
return ($this->redis->delete($cachekey) > 0);
|
||||
}
|
||||
|
||||
public function clear()
|
||||
public function clear($outdated = true)
|
||||
{
|
||||
return $this->redis->flushAll();
|
||||
if ($outdated) {
|
||||
return true;
|
||||
} else {
|
||||
return $this->redis->flushAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* (@inheritdoc)
|
||||
*/
|
||||
|
@ -92,7 +95,7 @@ class RedisCacheDriver extends AbstractCacheDriver implements IMemoryCacheDriver
|
|||
$cachekey = $this->getCacheKey($key);
|
||||
$cached = json_encode($value);
|
||||
|
||||
return $this->redis->setnx($cachekey, $value);
|
||||
return $this->redis->setnx($cachekey, $cached);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue