? .directory
? drupal-cache.inc-762978-D6.patch
? drupal-cache.inc-D6.patch
? drupal-common.inc-639974-D6.patch
Index: includes/cache.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/cache.inc,v
retrieving revision 1.17.2.4
diff -u -p -r1.17.2.4 cache.inc
--- includes/cache.inc	16 Dec 2009 17:30:00 -0000	1.17.2.4
+++ includes/cache.inc	6 Apr 2010 01:06:48 -0000
@@ -2,6 +2,29 @@
 // $Id: cache.inc,v 1.17.2.4 2009/12/16 17:30:00 goba Exp $
 
 /**
+ * Deletes caches from the cache_* table.
+ *
+ * If table is cache_page table then set it to have a grace period.
+ *
+ * @param $table
+ *   database table name
+ * @param $cache_flush
+ *   timestamp
+ */
+function cache_delete($table, $cache_flush) {
+  if ($table != 'cache_page') {
+    // Flush current entries by setting the created time to < 0
+    db_query("DELETE FROM {". $table ."} WHERE expire != %d AND expire <= %d", CACHE_PERMANENT, $cache_flush);
+  }
+  else {
+    // Don't delete but set created time for pages with expire < 0
+    db_query("UPDATE {". $table ."} SET created = %d WHERE created > -10 AND expire != %d AND expire <= %d", -time(), CACHE_PERMANENT, $cache_flush);
+    // But delete those that are older than one hour
+    db_query("DELETE FROM {". $table ."} WHERE created <= -10 AND created > %d AND expire != %d AND expire <= %d", -(time() - variable_get('cache_lifetime', 60*60)), CACHE_PERMANENT, $cache_flush);
+  }
+}
+
+/**
  * Return data from the persistent cache. Data may be stored as either plain text or as serialized data.
  * cache_get will automatically return unserialized objects and arrays.
  *
@@ -20,7 +43,7 @@ function cache_get($cid, $table = 'cache
     // Reset the variable immediately to prevent a meltdown in heavy load situations.
     variable_set('cache_flush_'. $table, 0);
     // Time to flush old cache data
-    db_query("DELETE FROM {". $table ."} WHERE expire != %d AND expire <= %d", CACHE_PERMANENT, $cache_flush);
+    cache_delete($table, $cache_flush);
   }
 
   $cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {". $table ."} WHERE cid = '%s'", $cid));
@@ -40,6 +63,10 @@ function cache_get($cid, $table = 'cache
     // sess_read() in session.inc.
     else {
       if ($user->cache > $cache->created) {
+        if ($table == 'cache_page') {
+          // To avoid too many people updating the page, temporarily set the created time 15 seconds in the future
+          db_query("UPDATE {".$table."} SET created = %d WHERE cid='%s'", (time() + 15), $cid);
+        }
         // This cache data is too old and thus not valid for us, ignore it.
         return 0;
       }
@@ -157,19 +184,24 @@ function cache_clear_all($cid = NULL, $t
       else if (time() > ($cache_flush + variable_get('cache_lifetime', 0))) {
         // Clear the cache for everyone, cache_lifetime seconds have
         // passed since the first request to clear the cache.
-        db_query("DELETE FROM {". $table ."} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, time());
+        cache_delete($table, time());
         variable_set('cache_flush_'. $table, 0);
       }
     }
     else {
       // No minimum cache lifetime, flush all temporary cache entries now.
-      db_query("DELETE FROM {". $table ."} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, time());
+      cache_delete($table, time());
     }
   }
   else {
     if ($wildcard) {
       if ($cid == '*') {
-        db_query("TRUNCATE TABLE {". $table ."}");
+        if ($table != 'cache_page') {
+          db_query("TRUNCATE TABLE {". $table ."}");
+        }
+        else {
+          cache_delete($table, time());
+        }
       }
       else {
         db_query("DELETE FROM {". $table ."} WHERE cid LIKE '%s%%'", $cid);
@@ -180,4 +212,3 @@ function cache_clear_all($cid = NULL, $t
     }
   }
 }
-
