Skip to content

Commit

Permalink
Merge pull request #12331 from totten/master-default-prefix
Browse files Browse the repository at this point in the history
(dev/core#174) CRM_Utils_Cache - Always use a prefix. Standardize delimiter
  • Loading branch information
eileenmcnaughton authored Jun 21, 2018
2 parents b7b5b7b + 1d521e7 commit 74a8b12
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CRM/Cxn/CiviCxnHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,11 @@ protected function createStreamOpts($verb, $url, $blob, $headers) {
return $result;
}

/**
* @return \CRM_Utils_Cache_Interface|null
*/
public function getCache() {
return $this->cache;
}

}
6 changes: 5 additions & 1 deletion CRM/Utils/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
* Cache is an empty base object, we'll modify the scheme when we have different caching schemes
*/
class CRM_Utils_Cache {

const DELIMITER = '/';

/**
* (Quasi-Private) Treat this as private. It is marked public to facilitate testing.
*
Expand Down Expand Up @@ -83,6 +86,7 @@ public static function &singleton() {
// a generic method for utilizing any of the available db caches.
$dbCacheClass = 'CRM_Utils_Cache_' . $className;
$settings = self::getCacheSettings($className);
$settings['prefix'] = CRM_Utils_Array::value('prefix', $settings, '') . self::DELIMITER . 'default' . self::DELIMITER;
self::$_singleton = new $dbCacheClass($settings);
}
return self::$_singleton;
Expand Down Expand Up @@ -186,7 +190,7 @@ public static function create($params = array()) {
if (defined('CIVICRM_DB_CACHE_CLASS') && in_array(CIVICRM_DB_CACHE_CLASS, array('Memcache', 'Memcached', 'Redis'))) {
$dbCacheClass = 'CRM_Utils_Cache_' . CIVICRM_DB_CACHE_CLASS;
$settings = self::getCacheSettings(CIVICRM_DB_CACHE_CLASS);
$settings['prefix'] = $settings['prefix'] . '_' . $params['name'];
$settings['prefix'] = CRM_Utils_Array::value('prefix', $settings, '') . self::DELIMITER . $params['name'] . self::DELIMITER;
return new $dbCacheClass($settings);
}
break;
Expand Down
8 changes: 6 additions & 2 deletions CRM/Utils/Cache/SqlGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,16 @@ public function getFromFrontCache($key, $default = NULL) {
* @param string $key
*/
public function delete($key) {
CRM_Core_BAO_Cache::deleteGroup($this->group, $key);
CRM_Core_BAO_Cache::deleteGroup($this->group, $key, FALSE);
CRM_Core_BAO_Cache::$_cache = NULL; // FIXME: remove multitier cache
CRM_Utils_Cache::singleton()->flush(); // FIXME: remove multitier cache
unset($this->frontCache[$key]);
}

public function flush() {
CRM_Core_BAO_Cache::deleteGroup($this->group);
CRM_Core_BAO_Cache::deleteGroup($this->group, NULL, FALSE);
CRM_Core_BAO_Cache::$_cache = NULL; // FIXME: remove multitier cache
CRM_Utils_Cache::singleton()->flush(); // FIXME: remove multitier cache
$this->frontCache = array();
}

Expand Down
10 changes: 8 additions & 2 deletions CRM/Utils/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -1416,8 +1416,14 @@ public static function civiExit($status = 0) {
public static function flushCache() {
// flush out all cache entries so we can reload new data
// a bit aggressive, but livable for now
$cache = CRM_Utils_Cache::singleton();
$cache->flush();
CRM_Utils_Cache::singleton()->flush();
if (Civi\Core\Container::isContainerBooted()) {
Civi::cache('settings')->flush();
Civi::cache('js_strings')->flush();
Civi::cache('community_messages')->flush();
CRM_Extension_System::singleton()->getCache()->flush();
CRM_Cxn_CiviCxnHttp::singleton()->getCache()->flush();
}

// also reset the various static memory caches

Expand Down

0 comments on commit 74a8b12

Please sign in to comment.