Always cleanup stale contribution-related page caches
authoradixon <alan.g.dixon@gmail.com>
Mon, 13 Jun 2016 16:27:21 +0000 (12:27 -0400)
committeradixon <alan.g.dixon@gmail.com>
Thu, 18 Aug 2016 15:39:17 +0000 (11:39 -0400)
CRM/Core/BAO/Cache.php

index 1977bf8c4612ea45c7d0217e36986a3c9089a6a0..41b711e62d32946e55169d76f63a05cac43984fa 100644 (file)
@@ -298,18 +298,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;
@@ -329,30 +355,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