X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FBAO%2FCache.php;h=e4c986ac2c29407a651ae61278af2289db525e3d;hb=d5f6077993b1df66a934933af0bc9327cff13e78;hp=e7323eaaa0549c4d29e98c33a877fd9d8c0777cf;hpb=64da89bd986c69172f768f41a3a894e4f4be39aa;p=civicrm-core.git diff --git a/CRM/Core/BAO/Cache.php b/CRM/Core/BAO/Cache.php index e7323eaaa0..e4c986ac2c 100644 --- a/CRM/Core/BAO/Cache.php +++ b/CRM/Core/BAO/Cache.php @@ -1,9 +1,9 @@ $cacheValue) + */ + static $_cache = NULL; + /** * Retrieve an item from the DB cache * @@ -58,16 +63,15 @@ class CRM_Core_BAO_Cache extends CRM_Core_DAO_Cache { * @access public */ static function &getItem($group, $path, $componentID = NULL) { - static $_cache = NULL; - if ($_cache === NULL) { - $_cache = array(); + if (self::$_cache === NULL) { + self::$_cache = array(); } - + $argString = "CRM_CT_{$group}_{$path}_{$componentID}"; - if (!array_key_exists($argString, $_cache)) { + if (!array_key_exists($argString, self::$_cache)) { $cache = CRM_Utils_Cache::singleton(); - $_cache[$argString] = $cache->get($argString); - if (!$_cache[$argString]) { + self::$_cache[$argString] = $cache->get($argString); + if (!self::$_cache[$argString]) { $dao = new CRM_Core_DAO_Cache(); $dao->group_name = $group; @@ -79,11 +83,11 @@ class CRM_Core_BAO_Cache extends CRM_Core_DAO_Cache { $data = unserialize($dao->data); } $dao->free(); - $_cache[$argString] = $data; - $cache->set($argString, $_cache[$argString]); + self::$_cache[$argString] = $data; + $cache->set($argString, self::$_cache[$argString]); } } - return $_cache[$argString]; + return self::$_cache[$argString]; } /** @@ -97,16 +101,15 @@ class CRM_Core_BAO_Cache extends CRM_Core_DAO_Cache { * @access public */ static function &getItems($group, $componentID = NULL) { - static $_cache = NULL; - if ($_cache === NULL) { - $_cache = array(); + if (self::$_cache === NULL) { + self::$_cache = array(); } - + $argString = "CRM_CT_CI_{$group}_{$componentID}"; - if (!array_key_exists($argString, $_cache)) { + if (!array_key_exists($argString, self::$_cache)) { $cache = CRM_Utils_Cache::singleton(); - $_cache[$argString] = $cache->get($argString); - if (!$_cache[$argString]) { + self::$_cache[$argString] = $cache->get($argString); + if (!self::$_cache[$argString]) { $dao = new CRM_Core_DAO_Cache(); $dao->group_name = $group; @@ -118,13 +121,13 @@ class CRM_Core_BAO_Cache extends CRM_Core_DAO_Cache { $result[$dao->path] = unserialize($dao->data); } $dao->free(); - - $_cache[$argString] = $result; - $cache->set($argString, $_cache[$argString]); + + self::$_cache[$argString] = $result; + $cache->set($argString, self::$_cache[$argString]); } } - return $_cache[$argString]; + return self::$_cache[$argString]; } /** @@ -140,9 +143,8 @@ class CRM_Core_BAO_Cache extends CRM_Core_DAO_Cache { * @access public */ static function setItem(&$data, $group, $path, $componentID = NULL) { - static $_cache = NULL; - if ($_cache === NULL) { - $_cache = array(); + if (self::$_cache === NULL) { + self::$_cache = array(); } $dao = new CRM_Core_DAO_Cache(); @@ -169,10 +171,17 @@ class CRM_Core_BAO_Cache extends CRM_Core_DAO_Cache { $dao->free(); - // set the cache in memory + // cache coherency - refresh or remove dependent caches + $argString = "CRM_CT_{$group}_{$path}_{$componentID}"; $cache = CRM_Utils_Cache::singleton(); - $cache->set($argString, $dao->data); + $data = unserialize($dao->data); + self::$_cache[$argString] = $data; + $cache->set($argString, $data); + + $argString = "CRM_CT_CI_{$group}_{$componentID}"; + unset(self::$_cache[$argString]); + $cache->delete($argString); } /** @@ -180,8 +189,8 @@ class CRM_Core_BAO_Cache extends CRM_Core_DAO_Cache { * delete the entire cache if group is not specified * * @param string $group The group name of the entries to be deleted - * @param string $path path of the item that needs to be deleted - * @param booleab $clearAll clear all caches + * @param string $path path of the item that needs to be deleted + * @param bool|\booleab $clearAll clear all caches * * @return void * @static @@ -294,6 +303,10 @@ class CRM_Core_BAO_Cache extends CRM_Core_DAO_Cache { * Do periodic cleanup of the CiviCRM session table. Also delete all session cache entries * which are a couple of days old. This keeps the session cache to a manageable size * + * @param bool $session + * @param bool $table + * @param bool $prevNext + * * @return void * @static * @access private