commit 0446ce97cb4d082d8d07f4bc717994491094c7fd
Author: Damien Tournoud <damien@commerceguys.com>
Date:   Mon Aug 15 15:27:38 2011 +0200

    Issue #1015946: fix the rotten minimum cache lifetime.

diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index fd0ae33..ce813a6 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -1837,7 +1837,6 @@ function drupal_anonymous_user() {
   $user->hostname = ip_address();
   $user->roles = array();
   $user->roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user';
-  $user->cache = 0;
   return $user;
 }
 
diff --git a/includes/cache.inc b/includes/cache.inc
index 8666874..59dc912 100644
--- a/includes/cache.inc
+++ b/includes/cache.inc
@@ -357,9 +357,26 @@ class DrupalDatabaseCache implements DrupalCacheInterface {
    *   The bin being requested.
    */
   protected function garbageCollection() {
-    global $user;
+    // Garbage collection is only necessary when enforcing a minimum cache lifetime.
+    $cache_lifetime = variable_get('cache_lifetime', 0);
+    if (!$cache_lifetime) {
+      return;
+    }
+
+    // Clean-up the per-user cache flush session data, so that the session
+    // handler can properly clean-up the session for anonymous users.
+    if (isset($_SESSION['cache_flush'])) {
+      $expire = REQUEST_TIME - $cache_lifetime;
+      foreach ($_SESSION['cache_flush'] as $bin => $timestamp) {
+        if ($timestamp < $expire) {
+          unset($_SESSION['cache_flush'][$bin]);
+        }
+      }
+      if (!$_SESSION['cache_flush']) {
+        unset($_SESSION['cache_flush']);
+      }
+    }
 
-    // Garbage collection necessary when enforcing a minimum cache lifetime.
     $cache_flush = variable_get('cache_flush_' . $this->bin, 0);
     if ($cache_flush && ($cache_flush + variable_get('cache_lifetime', 0) <= REQUEST_TIME)) {
       // Reset the variable immediately to prevent a meltdown in heavy load situations.
@@ -396,7 +413,7 @@ class DrupalDatabaseCache implements DrupalCacheInterface {
     // timer. The cache variable is loaded into the $user object by _drupal_session_read()
     // in session.inc. If the data is permanent or we're not enforcing a minimum
     // cache lifetime always return the cached data.
-    if ($cache->expire != CACHE_PERMANENT && variable_get('cache_lifetime', 0) && $user->cache > $cache->created) {
+    if ($cache->expire != CACHE_PERMANENT && variable_get('cache_lifetime', 0) && isset($_SESSION['cache_flush'][$this->bin]) && $_SESSION['cache_flush'][$this->bin] > $cache->created) {
       // This cache data is too old and thus not valid for us, ignore it.
       return FALSE;
     }
@@ -439,11 +456,10 @@ class DrupalDatabaseCache implements DrupalCacheInterface {
 
     if (empty($cid)) {
       if (variable_get('cache_lifetime', 0)) {
-        // We store the time in the current user's $user->cache variable which
-        // will be saved into the sessions bin by _drupal_session_write(). We then
-        // simulate that the cache was flushed for this user by not returning
-        // cached data that was cached before the timestamp.
-        $user->cache = REQUEST_TIME;
+        // We store the time in the current user's session. We then simulate
+        // that the cache was flushed for this user by not returning cached
+        // data that was cached before the timestamp.
+        $_SESSION['cache_flush'][$this->bin] = REQUEST_TIME;
 
         $cache_flush = variable_get('cache_flush_' . $this->bin, 0);
         if ($cache_flush == 0) {
diff --git a/includes/session.inc b/includes/session.inc
index 2ede2ff..2c5703e 100644
--- a/includes/session.inc
+++ b/includes/session.inc
@@ -173,7 +173,6 @@ function _drupal_session_write($sid, $value) {
       // Either ssid or sid or both will be added from $key below.
       $fields = array(
         'uid' => $user->uid,
-        'cache' => isset($user->cache) ? $user->cache : 0,
         'hostname' => ip_address(),
         'session' => $value,
         'timestamp' => REQUEST_TIME,
diff --git a/modules/system/system.install b/modules/system/system.install
index 6d80c43..8cb570b 100644
--- a/modules/system/system.install
+++ b/modules/system/system.install
@@ -1470,12 +1470,6 @@ function system_schema() {
         'not null' => TRUE,
         'default' => 0,
       ),
-      'cache' => array(
-        'description' => "The time of this user's last post. This is used when the site has specified a minimum_cache_lifetime. See cache_get().",
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => 0,
-      ),
       'session' => array(
         'description' => 'The serialized contents of $_SESSION, an array of name/value pairs that persists across page requests by this session ID. Drupal loads $_SESSION from here at the start of each request and saves it at the end.',
         'type' => 'blob',
@@ -1623,10 +1617,10 @@ function system_update_last_removed() {
  */
 
 /**
- * Placeholder update to set the schema version to 8000.
+ * Remove the obsolete {session}.cache column.
  */
 function system_update_8000() {
-  // Fill in the first update to Drupal 8 when needed.
+  db_drop_field('session', 'cache');
 }
 
 /**
