Update spelling of htmlpurifier to be correct spelling
[civicrm-core.git] / CRM / Core / PrevNextCache / Sql.php
index 86e1034ff364569cd98a66eadeab701ab121ed78..6784826561026bac9278b3e3b72c1486b144933e 100644 (file)
  */
 class CRM_Core_PrevNextCache_Sql implements CRM_Core_PrevNextCache_Interface {
 
+  /**
+   * @var int
+   * Days for cache to llast forr
+   */
+  const cacheDays = 2;
+
   /**
    * Store the results of a SQL query in the cache.
    * @param string $cacheKey
@@ -272,4 +278,24 @@ ORDER BY id
     return $cids;
   }
 
+  /**
+   * @inheritDoc
+   */
+  public function cleanup() {
+    // clean up all prev next caches older than $cacheTimeIntervalDays days
+    // first find all the cacheKeys that match this
+    $sql = "
+      DELETE     pn, c
+      FROM       civicrm_cache c
+      INNER JOIN civicrm_prevnext_cache pn ON c.path = pn.cachekey
+      WHERE      c.group_name = %1
+      AND        c.created_date < date_sub( NOW( ), INTERVAL %2 day )
+    ";
+    $params = [
+      1 => [CRM_Core_BAO_Cache::cleanKey('CiviCRM Search PrevNextCache'), 'String'],
+      2 => [self::cacheDays, 'Integer'],
+    ];
+    CRM_Core_DAO::executeQuery($sql, $params);
+  }
+
 }