From 7da6da6666973efce1553237846aca06d497866d Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sun, 7 Oct 2018 22:14:05 +0200 Subject: [PATCH] Bugfixings for getAllKeys() --- src/Core/Cache.php | 2 +- src/Core/Cache/DatabaseCacheDriver.php | 8 ++++---- src/Core/Cache/ICacheDriver.php | 2 +- src/Core/Cache/MemcachedCacheDriver.php | 2 +- src/Core/Console/Cache.php | 1 + 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Core/Cache.php b/src/Core/Cache.php index 7b9f6edd2c..b239af7d60 100644 --- a/src/Core/Cache.php +++ b/src/Core/Cache.php @@ -53,7 +53,7 @@ class Cache extends \Friendica\BaseObject * * @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) { diff --git a/src/Core/Cache/DatabaseCacheDriver.php b/src/Core/Cache/DatabaseCacheDriver.php index 9966457467..d90c6e4f18 100644 --- a/src/Core/Cache/DatabaseCacheDriver.php +++ b/src/Core/Cache/DatabaseCacheDriver.php @@ -21,18 +21,18 @@ class DatabaseCacheDriver extends AbstractCacheDriver implements ICacheDriver if (empty($prefix)) { $where = ['`expires` >= ?', DateTimeFormat::utcNow()]; } 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); - $list = []; + $keys = []; while ($key = DBA::fetch($stmt)) { - array_push($list, $key['k']); + array_push($keys, $key['k']); } DBA::close($stmt); - return $list; + return $keys; } /** diff --git a/src/Core/Cache/ICacheDriver.php b/src/Core/Cache/ICacheDriver.php index 0a206559cc..2c04c59925 100644 --- a/src/Core/Cache/ICacheDriver.php +++ b/src/Core/Cache/ICacheDriver.php @@ -16,7 +16,7 @@ interface ICacheDriver * * @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); diff --git a/src/Core/Cache/MemcachedCacheDriver.php b/src/Core/Cache/MemcachedCacheDriver.php index 62c3892860..1a6b2a9aef 100644 --- a/src/Core/Cache/MemcachedCacheDriver.php +++ b/src/Core/Cache/MemcachedCacheDriver.php @@ -65,7 +65,7 @@ class MemcachedCacheDriver extends AbstractCacheDriver implements IMemoryCacheDr return $this->filterArrayKeysByPrefix($keys, $prefix); } else { logger('Memcached \'getAllKeys\' failed with ' . $this->memcached->getResultMessage(), LOGGER_ALL); - return null; + return []; } } diff --git a/src/Core/Console/Cache.php b/src/Core/Console/Cache.php index 459a27e20b..1d93c3c011 100644 --- a/src/Core/Console/Cache.php +++ b/src/Core/Console/Cache.php @@ -116,6 +116,7 @@ HELP; $count = 0; foreach ($keys as $key) { $this->out($key); + $count++; } $this->out($count . ' keys found'); -- 2.39.5