From a944a143a2a468db7f818b06f2d45eb1406ab0de Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 15 Sep 2015 20:53:53 -0700 Subject: [PATCH] Memcache for extension, setting, and string caches --- CRM/Extension/System.php | 2 +- CRM/Utils/Cache.php | 9 +++++++++ Civi/Core/Container.php | 2 +- Civi/Core/SettingsMetadata.php | 4 ++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CRM/Extension/System.php b/CRM/Extension/System.php index a04d63cb7c..6b4a07de85 100644 --- a/CRM/Extension/System.php +++ b/CRM/Extension/System.php @@ -244,7 +244,7 @@ class CRM_Extension_System { // Extension system starts before container. Manage our own cache. $this->cache = CRM_Utils_Cache::create(array( 'name' => $cacheGroup, - 'type' => array('SqlGroup', 'ArrayCache'), + 'type' => array('*memory*', 'SqlGroup', 'ArrayCache'), 'prefetch' => TRUE, )); } diff --git a/CRM/Utils/Cache.php b/CRM/Utils/Cache.php index 5caa450dbe..df0427c238 100644 --- a/CRM/Utils/Cache.php +++ b/CRM/Utils/Cache.php @@ -182,6 +182,15 @@ class CRM_Utils_Cache { foreach ($types as $type) { switch ($type) { + case '*memory*': + if (defined('CIVICRM_DB_CACHE_CLASS') && in_array(CIVICRM_DB_CACHE_CLASS, array('Memcache', 'Memcached'))) { + $dbCacheClass = 'CRM_Utils_Cache_' . CIVICRM_DB_CACHE_CLASS; + $settings = self::getCacheSettings(CIVICRM_DB_CACHE_CLASS); + $settings['prefix'] = $settings['prefix'] . '_' . $params['name']; + return new $dbCacheClass($settings); + } + break; + case 'SqlGroup': if (defined('CIVICRM_DSN') && CIVICRM_DSN) { return new CRM_Utils_Cache_SqlGroup(array( diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index e1d0132e02..5488a44567 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -180,7 +180,7 @@ class Container { array( array( 'name' => $cacheName, - 'type' => array('SqlGroup', 'ArrayCache'), + 'type' => array('*memory*', 'SqlGroup', 'ArrayCache'), ), ) ))->setFactoryClass('CRM_Utils_Cache')->setFactoryMethod('create'); diff --git a/Civi/Core/SettingsMetadata.php b/Civi/Core/SettingsMetadata.php index fd70a8ca99..1fe89496b3 100644 --- a/Civi/Core/SettingsMetadata.php +++ b/Civi/Core/SettingsMetadata.php @@ -75,9 +75,9 @@ class SettingsMetadata { // the caching into 'All' seems to be a duplicate of caching to // settingsMetadata__ - I think the reason was to cache all settings as defined & then those altered by a hook $settingsMetadata = $cache->get($cacheString); - $cached = ($settingsMetadata === NULL); + $cached = is_array($settingsMetadata); - if ($settingsMetadata === NULL) { + if (!$cached) { $settingsMetadata = $cache->get(self::ALL); if (empty($settingsMetadata)) { global $civicrm_root; -- 2.25.1