Memcache for extension, setting, and string caches
authorTim Otten <totten@civicrm.org>
Wed, 16 Sep 2015 03:53:53 +0000 (20:53 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 17 Sep 2015 22:49:32 +0000 (15:49 -0700)
CRM/Extension/System.php
CRM/Utils/Cache.php
Civi/Core/Container.php
Civi/Core/SettingsMetadata.php

index a04d63cb7c1f2f82af4e2a7f698ee5b141af00ec..6b4a07de85f3167974646dd79f3778b183d3871b 100644 (file)
@@ -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,
       ));
     }
index 5caa450dbec167a5aad48759f1c59d2c1eb06396..df0427c23862d95765ce28e99ede80c286e62950 100644 (file)
@@ -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(
index e1d0132e02c4f486496910c3d618590598151fd1..5488a44567d12dceb9bec4fc4d171823f2ef88ba 100644 (file)
@@ -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');
index fd70a8ca993396bab99e5859c284b6bb6c3bf3b3..1fe89496b3e7b016966a8a6ac5186f61b8447df4 100644 (file)
@@ -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;