From: adixon Date: Mon, 13 Jun 2016 16:27:21 +0000 (-0400) Subject: Always cleanup stale contribution-related page caches X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5e63631a6655a102b1cd95b2c809e317364bacb0;p=civicrm-core.git Always cleanup stale contribution-related page caches --- diff --git a/CRM/Core/BAO/Cache.php b/CRM/Core/BAO/Cache.php index acfca02dc7..489916d333 100644 --- a/CRM/Core/BAO/Cache.php +++ b/CRM/Core/BAO/Cache.php @@ -297,18 +297,44 @@ class CRM_Core_BAO_Cache extends CRM_Core_DAO_Cache { * * Also delete all session cache entries which are a couple of days old. * This keeps the session cache to a manageable size + * Delete Contribution page session caches more energetically. * * @param bool $session * @param bool $table * @param bool $prevNext */ public static function cleanup($session = FALSE, $table = FALSE, $prevNext = FALSE) { + // first delete all sessions more than 20 minutes old which are related to any potential transaction + $timeIntervalMins = 20; + if (TRUE) { + $transactionPages = array( + 'CRM_Contribute_Controller_Contribution', + 'CRM_Event_Controller_Registration', + ); + + $params = array( + 1 => array( + date('Y-m-d H:i:s', time() - $timeIntervalMins * 60), + 'String', + ), + ); + foreach ($transactionPages as $trPage) { + $params[] = array("%${trPage}%", 'String'); + $where[] = 'path LIKE %' . count($params); + } + + $sql = " +DELETE FROM civicrm_cache +WHERE group_name = 'CiviCRM Session' +AND created_date <= %1 +AND (" . implode(' OR ', $where) . ")"; + CRM_Core_DAO::executeQuery($sql, $params); + } // clean up the session cache every $cacheCleanUpNumber probabilistically $cleanUpNumber = 757; // clean up all sessions older than $cacheTimeIntervalDays days $timeIntervalDays = 2; - $timeIntervalMins = 30; if (mt_rand(1, 100000) % $cleanUpNumber == 0) { $session = $table = $prevNext = TRUE; @@ -328,30 +354,6 @@ class CRM_Core_BAO_Cache extends CRM_Core_DAO_Cache { } if ($session) { - // first delete all sessions which are related to any potential transaction - // page - $transactionPages = array( - 'CRM_Contribute_Controller_Contribution', - 'CRM_Event_Controller_Registration', - ); - - $params = array( - 1 => array( - date('Y-m-d H:i:s', time() - $timeIntervalMins * 60), - 'String', - ), - ); - foreach ($transactionPages as $trPage) { - $params[] = array("%${trPage}%", 'String'); - $where[] = 'path LIKE %' . count($params); - } - - $sql = " -DELETE FROM civicrm_cache -WHERE group_name = 'CiviCRM Session' -AND created_date <= %1 -AND (" . implode(' OR ', $where) . ")"; - CRM_Core_DAO::executeQuery($sql, $params); $sql = " DELETE FROM civicrm_cache