From 8148791114a53750ec080191b391336077e68965 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sun, 8 Jul 2018 17:38:16 -0700 Subject: [PATCH] (dev/core#217) CRM_Utils_Cache - Extract method `getCacheDriver()` --- CRM/Utils/Cache.php | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/CRM/Utils/Cache.php b/CRM/Utils/Cache.php index 171e4d5437..358f260181 100644 --- a/CRM/Utils/Cache.php +++ b/CRM/Utils/Cache.php @@ -67,22 +67,7 @@ class CRM_Utils_Cache { */ public static function &singleton() { if (self::$_singleton === NULL) { - $className = 'ArrayCache'; // default to ArrayCache for now - - // Maintain backward compatibility for now. - // Setting CIVICRM_USE_MEMCACHE or CIVICRM_USE_ARRAYCACHE will - // override the CIVICRM_DB_CACHE_CLASS setting. - // Going forward, CIVICRM_USE_xxxCACHE should be deprecated. - if (defined('CIVICRM_USE_MEMCACHE') && CIVICRM_USE_MEMCACHE) { - $className = 'Memcache'; - } - elseif (defined('CIVICRM_USE_ARRAYCACHE') && CIVICRM_USE_ARRAYCACHE) { - $className = 'ArrayCache'; - } - elseif (defined('CIVICRM_DB_CACHE_CLASS') && CIVICRM_DB_CACHE_CLASS) { - $className = CIVICRM_DB_CACHE_CLASS; - } - + $className = self::getCacheDriver(); // a generic method for utilizing any of the available db caches. $dbCacheClass = 'CRM_Utils_Cache_' . $className; $settings = self::getCacheSettings($className); @@ -240,4 +225,30 @@ class CRM_Utils_Cache { return $key; } + /** + * @return string + * Ex: 'ArrayCache', 'Memcache', 'Redis'. + */ + public static function getCacheDriver() { + $className = 'ArrayCache'; // default to ArrayCache for now + + // Maintain backward compatibility for now. + // Setting CIVICRM_USE_MEMCACHE or CIVICRM_USE_ARRAYCACHE will + // override the CIVICRM_DB_CACHE_CLASS setting. + // Going forward, CIVICRM_USE_xxxCACHE should be deprecated. + if (defined('CIVICRM_USE_MEMCACHE') && CIVICRM_USE_MEMCACHE) { + $className = 'Memcache'; + return $className; + } + elseif (defined('CIVICRM_USE_ARRAYCACHE') && CIVICRM_USE_ARRAYCACHE) { + $className = 'ArrayCache'; + return $className; + } + elseif (defined('CIVICRM_DB_CACHE_CLASS') && CIVICRM_DB_CACHE_CLASS) { + $className = CIVICRM_DB_CACHE_CLASS; + return $className; + } + return $className; + } + } -- 2.25.1