From da4effce4adc75f03b2ecd825789ae35b5377662 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Wed, 19 Jun 2019 08:07:55 +1000 Subject: [PATCH] Convert prevNextCache to standard Cache Defintiion format --- CRM/Campaign/Selector/Search.php | 2 +- CRM/Contact/Selector.php | 2 +- CRM/Core/BAO/PrevNextCache.php | 2 +- Civi/Core/Container.php | 12 ++++++++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CRM/Campaign/Selector/Search.php b/CRM/Campaign/Selector/Search.php index 7c22820e9b..1342053314 100644 --- a/CRM/Campaign/Selector/Search.php +++ b/CRM/Campaign/Selector/Search.php @@ -296,7 +296,7 @@ FROM {$sql['from']} if (Civi::service('prevnext') instanceof CRM_Core_PrevNextCache_Sql) { // SQL-backed prevnext cache uses an extra record for pruning the cache. - CRM_Core_BAO_Cache::setItem($cacheKey, 'CiviCRM Search PrevNextCache', $cacheKey); + Civi::cache('prevNextCache')->set($cacheKey, $cacheKey); } } } diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php index a560a9adf3..ab894330c7 100644 --- a/CRM/Contact/Selector.php +++ b/CRM/Contact/Selector.php @@ -1063,7 +1063,7 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se if (Civi::service('prevnext') instanceof CRM_Core_PrevNextCache_Sql) { // SQL-backed prevnext cache uses an extra record for pruning the cache. - CRM_Core_BAO_Cache::setItem($cacheKey, 'CiviCRM Search PrevNextCache', $cacheKey); + Civi::cache('prevNextCache')->set($cacheKey, $cacheKey); } } diff --git a/CRM/Core/BAO/PrevNextCache.php b/CRM/Core/BAO/PrevNextCache.php index bfb410d993..3cc23eb301 100644 --- a/CRM/Core/BAO/PrevNextCache.php +++ b/CRM/Core/BAO/PrevNextCache.php @@ -424,7 +424,7 @@ WHERE c.group_name = %1 AND c.created_date < date_sub( NOW( ), INTERVAL %2 day ) "; $params = [ - 1 => ['CiviCRM Search PrevNextCache', 'String'], + 1 => [CRM_Core_BAO_Cache::cleanKey('CiviCRM Search PrevNextCache'), 'String'], 2 => [$cacheTimeIntervalDays, 'Integer'], ]; CRM_Core_DAO::executeQuery($sql, $params); diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index e2d8411a4f..0b00c77e6b 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -169,6 +169,18 @@ class Container { ))->setFactory('CRM_Utils_Cache::create'); } + // PrevNextCache cannot use memory or array cache at the moment because the + // Code in CRM_Core_BAO_PrevNextCache assumes that this cache is sql backed. + $container->setDefinition("cache.prevNextCache", new Definition( + 'CRM_Utils_Cache_Interface', + [ + [ + 'name' => 'CiviCRM Search PrevNextCache', + 'type' => ['SqlGroup'], + ], + ] + ))->setFactory('CRM_Utils_Cache::create'); + $container->setDefinition('sql_triggers', new Definition( 'Civi\Core\SqlTriggers', [] -- 2.25.1