From 124e528803354a61daf3f280ab282c4391e9e9bb Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 19 Jun 2018 16:06:26 -0700 Subject: [PATCH] (dev/core#174) CRM_Utils_Cache_Interface::flush() - Return bool like PSR-16 The function signature for `flush()` did not specify a return value, and actual behaviors varied depending on the driver (`bool` for memcache, `int` for redis, and `void` for others). This standardizes on returning a bool -- which makes the signature align with PSR-16's `clear()`. --- CRM/Utils/Cache/APCcache.php | 1 + CRM/Utils/Cache/ArrayCache.php | 1 + CRM/Utils/Cache/Interface.php | 2 ++ CRM/Utils/Cache/Memcache.php | 2 +- CRM/Utils/Cache/Memcached.php | 2 +- CRM/Utils/Cache/Redis.php | 5 +++-- CRM/Utils/Cache/SerializeCache.php | 4 +++- CRM/Utils/Cache/SqlGroup.php | 1 + 8 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CRM/Utils/Cache/APCcache.php b/CRM/Utils/Cache/APCcache.php index 8c36400dcd..0a3d3ee4b3 100644 --- a/CRM/Utils/Cache/APCcache.php +++ b/CRM/Utils/Cache/APCcache.php @@ -124,6 +124,7 @@ class CRM_Utils_Cache_APCcache implements CRM_Utils_Cache_Interface { apc_delete($this->_prefix . $name); } } + return TRUE; } } diff --git a/CRM/Utils/Cache/ArrayCache.php b/CRM/Utils/Cache/ArrayCache.php index d4bb268fbf..d196e5ef95 100644 --- a/CRM/Utils/Cache/ArrayCache.php +++ b/CRM/Utils/Cache/ArrayCache.php @@ -89,6 +89,7 @@ class CRM_Utils_Cache_Arraycache implements CRM_Utils_Cache_Interface { public function flush() { unset($this->_cache); $this->_cache = array(); + return TRUE; } } diff --git a/CRM/Utils/Cache/Interface.php b/CRM/Utils/Cache/Interface.php index 0f95b99ffd..0316abe7f1 100644 --- a/CRM/Utils/Cache/Interface.php +++ b/CRM/Utils/Cache/Interface.php @@ -86,6 +86,8 @@ interface CRM_Utils_Cache_Interface { /** * Delete all values from the cache. + * + * @return bool */ public function flush(); diff --git a/CRM/Utils/Cache/Memcache.php b/CRM/Utils/Cache/Memcache.php index c85b85559b..9444ca1335 100644 --- a/CRM/Utils/Cache/Memcache.php +++ b/CRM/Utils/Cache/Memcache.php @@ -150,7 +150,7 @@ class CRM_Utils_Cache_Memcache implements CRM_Utils_Cache_Interface { } /** - * @return mixed + * @return bool */ public function flush() { // FIXME: Only delete items matching `$this->_prefix`. diff --git a/CRM/Utils/Cache/Memcached.php b/CRM/Utils/Cache/Memcached.php index 876f6961e6..ff869f919e 100644 --- a/CRM/Utils/Cache/Memcached.php +++ b/CRM/Utils/Cache/Memcached.php @@ -172,7 +172,7 @@ class CRM_Utils_Cache_Memcached implements CRM_Utils_Cache_Interface { } /** - * @return mixed + * @return bool */ public function flush() { // FIXME: Only delete items matching `$this->_prefix`. diff --git a/CRM/Utils/Cache/Redis.php b/CRM/Utils/Cache/Redis.php index f0ee3f3792..6b50cc86d9 100644 --- a/CRM/Utils/Cache/Redis.php +++ b/CRM/Utils/Cache/Redis.php @@ -159,7 +159,7 @@ class CRM_Utils_Cache_Redis implements CRM_Utils_Cache_Interface { } /** - * @return mixed + * @return bool */ public function flush() { // FIXME: Ideally, we'd map each prefix to a different 'hash' object in Redis, @@ -167,7 +167,8 @@ class CRM_Utils_Cache_Redis implements CRM_Utils_Cache_Interface { // more general rethink of cache expiration/TTL. $keys = $this->_cache->keys($this->_prefix . '*'); - return $this->_cache->del($keys); + $this->_cache->del($keys); + return TRUE; } } diff --git a/CRM/Utils/Cache/SerializeCache.php b/CRM/Utils/Cache/SerializeCache.php index 7f6f63246f..906d9b7246 100644 --- a/CRM/Utils/Cache/SerializeCache.php +++ b/CRM/Utils/Cache/SerializeCache.php @@ -119,11 +119,12 @@ class CRM_Utils_Cache_SerializeCache implements CRM_Utils_Cache_Interface { /** * @param null $key + * @return bool */ public function flush($key = NULL) { $prefix = "CRM_"; if (!$handle = opendir(CIVICRM_TEMPLATE_COMPILEDIR)) { - return; // die? Error? + return FALSE; // die? Error? } while (FALSE !== ($entry = readdir($handle))) { if (substr($entry, 0, 4) == $prefix) { @@ -133,6 +134,7 @@ class CRM_Utils_Cache_SerializeCache implements CRM_Utils_Cache_Interface { closedir($handle); unset($this->_cache); $this->_cache = array(); + return TRUE; } } diff --git a/CRM/Utils/Cache/SqlGroup.php b/CRM/Utils/Cache/SqlGroup.php index 01a7637737..b4d943e451 100644 --- a/CRM/Utils/Cache/SqlGroup.php +++ b/CRM/Utils/Cache/SqlGroup.php @@ -144,6 +144,7 @@ class CRM_Utils_Cache_SqlGroup implements CRM_Utils_Cache_Interface { CRM_Core_BAO_Cache::$_cache = NULL; // FIXME: remove multitier cache CRM_Utils_Cache::singleton()->flush(); // FIXME: remove multitier cache $this->frontCache = array(); + return TRUE; } public function prefetch() { -- 2.25.1