Bugfixings for getAllKeys()
This commit is contained in:
parent
8491f8660f
commit
7da6da6666
|
@ -53,7 +53,7 @@ class Cache extends \Friendica\BaseObject
|
||||||
*
|
*
|
||||||
* @param string $prefix Prefix of the keys (optional)
|
* @param string $prefix Prefix of the keys (optional)
|
||||||
*
|
*
|
||||||
* @return array|null Null if the driver doesn't support this feature
|
* @return array Empty if the driver doesn't support this feature
|
||||||
*/
|
*/
|
||||||
public static function getAllKeys($prefix = null)
|
public static function getAllKeys($prefix = null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,18 +21,18 @@ class DatabaseCacheDriver extends AbstractCacheDriver implements ICacheDriver
|
||||||
if (empty($prefix)) {
|
if (empty($prefix)) {
|
||||||
$where = ['`expires` >= ?', DateTimeFormat::utcNow()];
|
$where = ['`expires` >= ?', DateTimeFormat::utcNow()];
|
||||||
} else {
|
} else {
|
||||||
$where = ['`expires` >= ? AND k LIKE CONCAT(?, \'%\')', DateTimeFormat::utcNow(), $prefix];
|
$where = ['`expires` >= ? AND `k` LIKE CONCAT(?, \'%\')', DateTimeFormat::utcNow(), $prefix];
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt = DBA::select('cache', ['k'], $where);
|
$stmt = DBA::select('cache', ['k'], $where);
|
||||||
|
|
||||||
$list = [];
|
$keys = [];
|
||||||
while ($key = DBA::fetch($stmt)) {
|
while ($key = DBA::fetch($stmt)) {
|
||||||
array_push($list, $key['k']);
|
array_push($keys, $key['k']);
|
||||||
}
|
}
|
||||||
DBA::close($stmt);
|
DBA::close($stmt);
|
||||||
|
|
||||||
return $list;
|
return $keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,7 +16,7 @@ interface ICacheDriver
|
||||||
*
|
*
|
||||||
* @param string prefix optional a prefix to search
|
* @param string prefix optional a prefix to search
|
||||||
*
|
*
|
||||||
* @return array|null Null if it isn't supported by the cache driver
|
* @return array Empty if it isn't supported by the cache driver
|
||||||
*/
|
*/
|
||||||
public function getAllKeys($prefix = null);
|
public function getAllKeys($prefix = null);
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ class MemcachedCacheDriver extends AbstractCacheDriver implements IMemoryCacheDr
|
||||||
return $this->filterArrayKeysByPrefix($keys, $prefix);
|
return $this->filterArrayKeysByPrefix($keys, $prefix);
|
||||||
} else {
|
} else {
|
||||||
logger('Memcached \'getAllKeys\' failed with ' . $this->memcached->getResultMessage(), LOGGER_ALL);
|
logger('Memcached \'getAllKeys\' failed with ' . $this->memcached->getResultMessage(), LOGGER_ALL);
|
||||||
return null;
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,7 @@ HELP;
|
||||||
$count = 0;
|
$count = 0;
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
$this->out($key);
|
$this->out($key);
|
||||||
|
$count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->out($count . ' keys found');
|
$this->out($count . ' keys found');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user