From febc8b36ffd6c2d4ae373f9bc8ad790c5acd004f Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 22 Jun 2019 09:05:52 +1000 Subject: [PATCH] Ensure that if we are ever clearing keys from civicrm_cache for prevNext that we also clear from civicrm_prev_next_cache if sqlBacked or just deleteItem if only deleting a single cache Key --- CRM/Utils/Cache/SqlGroup.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/CRM/Utils/Cache/SqlGroup.php b/CRM/Utils/Cache/SqlGroup.php index 7b4df7dcc9..fe34b5290c 100644 --- a/CRM/Utils/Cache/SqlGroup.php +++ b/CRM/Utils/Cache/SqlGroup.php @@ -213,6 +213,11 @@ class CRM_Utils_Cache_SqlGroup implements CRM_Utils_Cache_Interface { */ public function delete($key) { CRM_Utils_Cache::assertValidKey($key); + // If we are triggering a deletion of a prevNextCache key in the civicrm_cache tabl + // Alssure that the relevant prev_next_cache values are also removed. + if ($this->group == CRM_Core_BAO_Cache::cleanKey('CiviCRM Search PrevNextCache')) { + Civi::service('prevnext')->deleteItem(NULL, $key); + } CRM_Core_DAO::executeQuery("DELETE FROM {$this->table} WHERE {$this->where($key)}"); unset($this->valueCache[$key]); unset($this->expiresCache[$key]); @@ -220,7 +225,14 @@ class CRM_Utils_Cache_SqlGroup implements CRM_Utils_Cache_Interface { } public function flush() { - CRM_Core_DAO::executeQuery("DELETE FROM {$this->table} WHERE {$this->where()}"); + if ($this->group == CRM_Core_BAO_Cache::cleanKey('CiviCRM Search PrevNextCache') && + Civi::service('prevnext') instanceof CRM_Core_PrevNextCache_Sql) { + // Use the standard PrevNextCache cleanup function here not just delete from civicrm_cache + CRM_Core_BAO_PrevNextCache::cleanupCache(); + } + else { + CRM_Core_DAO::executeQuery("DELETE FROM {$this->table} WHERE {$this->where()}"); + } $this->valueCache = []; $this->expiresCache = []; return TRUE; -- 2.25.1