From 1d6391d2bce8b7ca0ee25790dc5d82a8c83a2333 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 2 Jul 2019 21:05:30 -0700 Subject: [PATCH] (dev/cloud-native#3) SerializeCache - Remove unused, incomplete cache-driver The class `CRM_Utils_Cache_SerializeCache` provides a cache-driver for storing cache records in the filesystem (under `CIVICRM_TEMPLATE_COMPILEDIR`, using PHP `serialize()` format). Why remove it? 1. As we work through cleanup in file management (e.g. #12843, dev/cloud-native#3), having an unnecessary reference to CIVICRM_TEMPLATE_COMPILEDIR makes it harder to reason about the system. 2. The class is not used. I'm pretty sure it was added speculatively (i.e. with an aim to try using it some day), but that never came to pass. Grepping `universe`, I cannot find any usages or references to `SerializeCache`. 3. The implementation is incomplete -- parameters like `get(..., $default)` and `set(..., $ttl)` will generate exceptions if used. --- CRM/Utils/Cache/SerializeCache.php | 151 ----------------------------- 1 file changed, 151 deletions(-) delete mode 100644 CRM/Utils/Cache/SerializeCache.php diff --git a/CRM/Utils/Cache/SerializeCache.php b/CRM/Utils/Cache/SerializeCache.php deleted file mode 100644 index f17b459107..0000000000 --- a/CRM/Utils/Cache/SerializeCache.php +++ /dev/null @@ -1,151 +0,0 @@ -_cache = []; - } - - /** - * @param $key - * - * @return string - */ - public function fileName($key) { - if (strlen($key) > 50) { - return CIVICRM_TEMPLATE_COMPILEDIR . "CRM_" . md5($key) . ".php"; - } - return CIVICRM_TEMPLATE_COMPILEDIR . $key . ".php"; - } - - /** - * @param string $key - * @param mixed $default - * - * @return mixed - */ - public function get($key, $default = NULL) { - if ($default !== NULL) { - throw new \RuntimeException("FIXME: " . __CLASS__ . "::get() only supports NULL default"); - } - - if (array_key_exists($key, $this->_cache)) { - return $this->_cache[$key]; - } - - if (!file_exists($this->fileName($key))) { - return; - } - $this->_cache[$key] = unserialize(substr(file_get_contents($this->fileName($key)), 8)); - return $this->_cache[$key]; - } - - /** - * @param string $key - * @param mixed $value - * @param null|int|\DateInterval $ttl - * @return bool - */ - public function set($key, $value, $ttl = NULL) { - if ($ttl !== NULL) { - throw new \RuntimeException("FIXME: " . __CLASS__ . "::set() should support non-NULL TTL"); - } - if (file_exists($this->fileName($key))) { - // WTF, write-once cache?! - return FALSE; - } - $this->_cache[$key] = $value; - $bytes = file_put_contents($this->fileName($key), "fileName($key))) { - unlink($this->fileName($key)); - } - unset($this->_cache[$key]); - return TRUE; - } - - /** - * @param null $key - * @return bool - */ - public function flush($key = NULL) { - $prefix = "CRM_"; - if (!$handle = opendir(CIVICRM_TEMPLATE_COMPILEDIR)) { - // die? Error? - return FALSE; - } - while (FALSE !== ($entry = readdir($handle))) { - if (substr($entry, 0, 4) == $prefix) { - unlink(CIVICRM_TEMPLATE_COMPILEDIR . $entry); - } - } - closedir($handle); - unset($this->_cache); - $this->_cache = []; - return TRUE; - } - - public function clear() { - return $this->flush(); - } - -} -- 2.25.1