* Various predefined settings that have been migrated to the setting table.
*/
const
+ ALL = 'all',
ADDRESS_STANDARDIZATION_PREFERENCES_NAME = 'Address Standardization Preferences',
CAMPAIGN_PREFERENCES_NAME = 'Campaign Preferences',
DEVELOPER_PREFERENCES_NAME = 'Developer Preferences',
$domainID = NULL,
$profile = NULL
) {
- $cacheString = 'settingsMetadata_' . $domainID . '_' . $profile;
+ $cache = Civi::cache('settings');
+
+ $cacheString = 'settingsMetadata_' . $domainID . '_' . $profile . '_' . $componentID;
foreach ($filters as $filterField => $filterString) {
$cacheString .= "_{$filterField}_{$filterString}";
}
$cached = 1;
// 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 = CRM_Core_BAO_Cache::getItem('CiviCRM setting Specs', $cacheString, $componentID);
+ $settingsMetadata = $cache->get($cacheString);
+
if ($settingsMetadata === NULL) {
- $settingsMetadata = CRM_Core_BAO_Cache::getItem('CiviCRM setting Spec', 'All', $componentID);
+ $settingsMetadata = $cache->get(self::ALL);
if (empty($settingsMetadata)) {
global $civicrm_root;
$metaDataFolders = array($civicrm_root . '/settings');
CRM_Utils_Hook::alterSettingsFolders($metaDataFolders);
$settingsMetadata = self::loadSettingsMetaDataFolders($metaDataFolders);
- CRM_Core_BAO_Cache::setItem($settingsMetadata, 'CiviCRM setting Spec', 'All', $componentID);
+ $cache->set(self::ALL, $settingsMetadata);
}
$cached = 0;
}
// this is a bit 'heavy' if you are using hooks but this function
// is expected to only be called during setting administration
// it should not be called by 'getvalue' or 'getitem
- CRM_Core_BAO_Cache::setItem(
- $settingsMetadata,
- 'CiviCRM setting Specs',
- $cacheString,
- $componentID
- );
+ $cache->set($cacheString, $settingsMetadata);
}
return $settingsMetadata;
$settings = include $file;
$settingMetaData = array_merge($settingMetaData, $settings);
}
- CRM_Core_BAO_Cache::setItem($settingMetaData, 'CiviCRM setting Spec', 'All');
+ Civi::cache('settings')->set(self::ALL, $settingMetaData);
return $settingMetaData;
}
*/
public static function create() {
return new CRM_Core_CommunityMessages(
- new CRM_Utils_Cache_SqlGroup(array(
- 'group' => 'community-messages',
- 'prefetch' => FALSE,
- )),
+ Civi::cache('community_messages'),
CRM_Utils_HttpClient::singleton()
);
}
}
if (self::$_singleton === NULL) {
$sys = CRM_Extension_System::singleton();
- $cache = new CRM_Utils_Cache_SqlGroup(array(
- 'group' => 'js-strings',
- 'prefetch' => FALSE,
- ));
+ $cache = Civi::cache('js_strings');
self::$_singleton = new CRM_Core_Resources(
$sys->getMapper(),
$cache,
*/
public static function singleton($fresh = FALSE) {
if (self::$singleton === NULL || $fresh) {
- $config = CRM_Core_Config::singleton();
-
- if ($config->debug) {
- $cache = new CRM_Utils_Cache_Arraycache(array());
- }
- else {
- $cache = new CRM_Utils_Cache_SqlGroup(array(
- 'group' => 'CiviCxnHttp',
- 'prefetch' => FALSE,
- ));
- }
+ $cache = CRM_Utils_Cache::create(array(
+ 'name' => 'CiviCxnHttp',
+ 'type' => Civi::settings()->get('debug_enabled') ? 'ArrayCache' : array('SqlGroup', 'ArrayCache'),
+ 'prefetch' => FALSE,
+ ));
self::$singleton = new CRM_Cxn_CiviCxnHttp($cache);
}
*/
public function getCache() {
if ($this->cache === NULL) {
- if (defined('CIVICRM_DSN')) {
- $cacheGroup = md5(serialize(array('ext', $this->parameters)));
- $this->cache = new CRM_Utils_Cache_SqlGroup(array(
- 'group' => $cacheGroup,
- 'prefetch' => TRUE,
- ));
- }
- else {
- $this->cache = new CRM_Utils_Cache_ArrayCache(array());
- }
+ $cacheGroup = md5(serialize(array('ext', $this->parameters)));
+ // Extension system starts before container. Manage our own cache.
+ $this->cache = CRM_Utils_Cache::create(array(
+ 'name' => $cacheGroup,
+ 'type' => array('SqlGroup', 'ArrayCache'),
+ 'prefetch' => TRUE,
+ ));
}
return $this->cache;
}
return $defaults;
}
+ /**
+ * Create a new, named, limited-use cache.
+ *
+ * This is a factory function. Generally, you should use Civi::cache($name)
+ * to locate managed cached instance.
+ *
+ * @param array $params
+ * Array with keys:
+ * - name: string, unique symbolic name.
+ * - type: array|string, list of acceptable cache types, in order of preference.
+ * - prefetch: bool, whether to prefetch all data in cache (if possible).
+ * @return CRM_Utils_Cache_Interface
+ * @throws CRM_Core_Exception
+ * @see Civi::cache()
+ */
+ public static function create($params = array()) {
+ $types = (array) $params['type'];
+
+ foreach ($types as $type) {
+ switch ($type) {
+ case 'SqlGroup':
+ if (defined('CIVICRM_DSN') && CIVICRM_DSN) {
+ return new CRM_Utils_Cache_SqlGroup(array(
+ 'group' => $params['name'],
+ 'prefetch' => CRM_Utils_Array::value('prefetch', $params, FALSE),
+ ));
+ }
+ break;
+
+ case 'Arraycache':
+ case 'ArrayCache':
+ return new CRM_Utils_Cache_ArrayCache(array());
+
+ }
+ }
+
+ throw new CRM_Core_Exception("Failed to instantiate cache. No supported cache type found. " . print_r($params, 1));
+ }
+
}
$container->setDefinition('psr_log', new Definition('CRM_Core_Error_Log', array()));
- $container->setDefinition('cache.settings', new Definition(
- 'CRM_Utils_Cache_SqlGroup',
- array(
- array('group' => 'Settings', 'prefetch' => 0),
- )
- ));
+ foreach (array('settings', 'js_strings', 'community_messages') as $cacheName) {
+ $container->setDefinition("cache.{$cacheName}", new Definition(
+ 'CRM_Utils_Cache_Interface',
+ array(
+ array(
+ 'name' => $cacheName,
+ 'type' => array('SqlGroup', 'ArrayCache'),
+ ),
+ )
+ ))->setFactoryClass('CRM_Utils_Cache')->setFactoryMethod('create');
+ }
$container->setDefinition('settings_manager', new Definition(
'Civi\Core\SettingsManager',