Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.192
diff -u -p -r1.192 bootstrap.inc
--- includes/bootstrap.inc	10 Sep 2007 12:19:11 -0000	1.192
+++ includes/bootstrap.inc	2 Oct 2007 12:57:17 -0000
@@ -567,7 +567,7 @@ function drupal_load($type, $name) {
  */
 function drupal_page_header() {
   header("Expires: Sun, 19 Nov 1978 05:00:00 GMT");
-  header("Last-Modified: ". gmdate("D, d M Y H:i:s") ." GMT");
+  header("Last-Modified: ". gmdate("D, d M Y H:i:s", drupal_get_page_last_modified()) ." GMT");
   header("Cache-Control: store, no-cache, must-revalidate");
   header("Cache-Control: post-check=0, pre-check=0", FALSE);
 }
@@ -583,7 +583,7 @@ function drupal_page_header() {
  */
 function drupal_page_cache_header($cache) {
   // Set default values:
-  $last_modified = gmdate('D, d M Y H:i:s', $cache->created) .' GMT';
+  $last_modified = gmdate('D, d M Y H:i:s', $cache->last_modified) .' GMT';
   $etag = '"'. md5($last_modified) .'"';
 
   // See if the client has provided the required HTTP headers:
@@ -628,6 +628,42 @@ function drupal_page_cache_header($cache
 }
 
 /**
+ * Set a page's age
+ *
+ * Call this function if you want to set the timestamp of a pages age.
+ *
+ * @param $date a timestamp
+ *
+ * @return the highest timestamp passed into this function so far.
+ */
+function drupal_set_page_last_modified($date = 0) {
+  static $cache_date = 0;
+
+  if ($date > $cache_date) {
+    $cache_date = $date;
+  }
+
+  return $cache_date;
+}
+
+/**
+ * Get cache date
+ *
+ * @return the highest timestamp passed into drupal_set_page_last_modified so far or the current time.
+ */
+function drupal_get_page_last_modified() {
+  $date = drupal_set_page_last_modified();
+  $time = time();
+
+  if ($date < $time && $date > 0) {
+    return $date;
+  }
+  else {
+    return $time;
+  }
+}
+
+/**
  * Define the critical hooks that force modules to always be loaded.
  */
 function bootstrap_hooks() {
Index: includes/cache.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/cache.inc,v
retrieving revision 1.14
diff -u -p -r1.14 cache.inc
--- includes/cache.inc	26 Aug 2007 09:33:49 -0000	1.14
+++ includes/cache.inc	2 Oct 2007 12:57:17 -0000
@@ -22,7 +22,7 @@ function cache_get($cid, $table = 'cache
     variable_set('cache_flush', 0);
   }
 
-  $cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {". $table ."} WHERE cid = '%s'", $cid));
+  $cache = db_fetch_object(db_query("SELECT data, created, last_modified, headers, expire, serialized FROM {". $table ."} WHERE cid = '%s'", $cid));
   if (isset($cache->data)) {
     // If the data is permanent or we're not enforcing a minimum cache lifetime
     // always return the cached data.
@@ -105,9 +105,11 @@ function cache_set($cid, $data, $table =
     $serialized = 1;
   }
   $created = time();
-  db_query("UPDATE {". $table ."} SET data = %b, created = %d, expire = %d, headers = '%s', serialized = %d WHERE cid = '%s'", $data, $created, $expire, $headers, $serialized, $cid);
+  $last_modified = drupal_get_page_last_modified();
+#  var_dump("last_modified $cid");
+  db_query("UPDATE {". $table ."} SET data = %b, created = %d, last_modified = %d, expire = %d, headers = '%s', serialized = %d WHERE cid = '%s'", $data, $created, $last_modified, $expire, $headers, $serialized, $cid);
   if (!db_affected_rows()) {
-    @db_query("INSERT INTO {". $table ."} (cid, data, created, expire, headers, serialized) VALUES ('%s', %b, %d, %d, '%s', %d)", $cid, $data, $created, $expire, $headers, $serialized);
+    @db_query("INSERT INTO {". $table ."} (cid, data, created, last_modified, expire, headers, serialized) VALUES ('%s', %b, %d, %d, %d, '%s', %d)", $cid, $data, $created, $last_modified, $expire, $headers, $serialized);
   }
 }
 
Index: modules/block/block.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.module,v
retrieving revision 1.278
diff -u -p -r1.278 block.module
--- modules/block/block.module	27 Sep 2007 16:52:00 -0000	1.278
+++ modules/block/block.module	2 Oct 2007 12:57:18 -0000
@@ -431,9 +431,11 @@ function block_list($region) {
           // by fetching from cache only if the request method is 'GET'.
           if (!count(module_implements('node_grants')) && $_SERVER['REQUEST_METHOD'] == 'GET' && ($cid = _block_get_cache_id($block)) && ($cache = cache_get($cid, 'cache_block'))) {
             $array = $cache->data;
+            drupal_set_page_last_modified($cache->last_modified);
           }
           else {
             $array = module_invoke($block->module, 'block', 'view', $block->delta);
+            watchdog('debug', "block cid $block->module $block->delta $cid");
             if (isset($cid)) {
               cache_set($cid, $array, 'cache_block', CACHE_TEMPORARY);
             }
@@ -487,7 +489,6 @@ function _block_get_cache_id($block) {
   // block caching.
   if (variable_get('block_cache', 0) && $block->cache != BLOCK_NO_CACHE && $user->uid != 1) {
     $cid_parts = array();
-
     // Start with common sub-patterns: block identification, theme, language.
     $cid_parts[] = $block->module;
     $cid_parts[] = $block->delta;
@@ -511,6 +512,7 @@ function _block_get_cache_id($block) {
       $cid_parts[] = $base_root . request_uri();
     }
 
+    watchdog('debug', implode(',', $cid_parts));
     return implode(':', $cid_parts);
   }
 }
\ No newline at end of file
Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.585
diff -u -p -r1.585 comment.module
--- modules/comment/comment.module	28 Sep 2007 17:15:04 -0000	1.585
+++ modules/comment/comment.module	2 Oct 2007 12:57:19 -0000
@@ -495,6 +495,9 @@ function comment_form_alter(&$form, $for
  */
 function comment_nodeapi(&$node, $op, $arg = 0) {
   switch ($op) {
+    case 'view':
+      drupal_set_page_last_modified($node->last_comment_timestamp);
+      break;
     case 'load':
       return db_fetch_array(db_query("SELECT last_comment_timestamp, last_comment_name, comment_count FROM {node_comment_statistics} WHERE nid = %d", $node->nid));
       break;
@@ -1002,6 +1005,7 @@ function comment_render($node, $cid = 0)
     $mode = _comment_get_display_setting('mode');
     $order = _comment_get_display_setting('sort');
     $comments_per_page = _comment_get_display_setting('comments_per_page');
+    $latest = 0;
 
     if ($cid && is_numeric($cid)) {
       // Single comment view.
@@ -1019,6 +1023,7 @@ function comment_render($node, $cid = 0)
         $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
         $links = module_invoke_all('link', 'comment', $comment, 1);
         drupal_alter('link', $links, $node);
+        $latest = ($comment->timestamp > $latest) ? $comment->timestamp : $latest;
 
         $output .= theme('comment_view', $comment, $node, $links);
       }
@@ -1089,6 +1094,8 @@ function comment_render($node, $cid = 0)
           }
         }
 
+        $latest = ($comment->timestamp > $latest) ? $comment->timestamp : $latest;
+
         if ($mode == COMMENT_MODE_FLAT_COLLAPSED) {
           $comments .= theme('comment_flat_collapsed', $comment, $node);
         }
@@ -1126,6 +1133,8 @@ function comment_render($node, $cid = 0)
     }
 
     $output = theme('comment_wrapper', $output, $node);
+
+    drupal_set_page_last_modified($latest);
   }
 
   return $output;
@@ -1310,6 +1319,8 @@ function theme_comment_admin_overview($f
       $row[] = drupal_render($form['operations'][$key]);
       $rows[] = $row;
     }
+
+    drupal_set_page_last_modified($latest);
   }
   else {
     $rows[] = array(array('data' => t('No comments available.'), 'colspan' => '6'));
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.888
diff -u -p -r1.888 node.module
--- modules/node/node.module	27 Sep 2007 12:56:04 -0000	1.888
+++ modules/node/node.module	2 Oct 2007 12:57:20 -0000
@@ -942,6 +942,8 @@ function node_view($node, $teaser = FALS
   // Allow modules to modify the fully-built node.
   node_invoke_nodeapi($node, 'alter', $teaser, $page);
 
+  drupal_set_page_last_modified($node->changed);
+
   return theme('node', $node, $teaser, $page);
 }
 
@@ -990,6 +992,8 @@ function node_build_content($node, $teas
     $node->build_mode = NODE_BUILD_NORMAL;
   }
 
+  drupal_set_page_last_modified($node->changed);
+
   // Remove the delimiter (if any) that separates the teaser from the body.
   $node->body = isset($node->body) ? str_replace('<!--break-->', '', $node->body) : '';
 
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.156
diff -u -p -r1.156 system.install
--- modules/system/system.install	26 Sep 2007 20:01:17 -0000	1.156
+++ modules/system/system.install	2 Oct 2007 12:57:21 -0000
@@ -3778,6 +3778,20 @@ function system_update_6033() {
 
 
 /**
+ * Add last_modified timestamp to cache tables.
+ */
+function system_update_6034() {
+  $ret = array();
+  db_add_field($ret, 'cache_block', 'last_modified', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+  db_add_field($ret, 'cache_filter', 'last_modified', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+  db_add_field($ret, 'cache_form', 'last_modified', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+  db_add_field($ret, 'cache_menu', 'last_modified', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+  db_add_field($ret, 'cache_page', 'last_modified', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+  db_add_field($ret, 'cache_update', 'last_modified', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+  return $ret;
+}
+
+/**
  * @} End of "defgroup updates-5.x-to-6.x"
  * The next series of updates should start at 7000.
  */
Index: modules/system/system.schema
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.schema,v
retrieving revision 1.13
diff -u -p -r1.13 system.schema
--- modules/system/system.schema	11 Sep 2007 19:14:34 -0000	1.13
+++ modules/system/system.schema	2 Oct 2007 12:57:21 -0000
@@ -48,6 +48,7 @@ function system_schema() {
       'data'       => array('type' => 'blob', 'not null' => FALSE, 'size' => 'big'),
       'expire'     => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
       'created'    => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+      'last_modified'  => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
       'headers'    => array('type' => 'text', 'not null' => FALSE),
       'serialized' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)
     ),
Index: modules/tracker/tracker.pages.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/tracker/tracker.pages.inc,v
retrieving revision 1.2
diff -u -p -r1.2 tracker.pages.inc
--- modules/tracker/tracker.pages.inc	2 Sep 2007 14:56:18 -0000	1.2
+++ modules/tracker/tracker.pages.inc	2 Oct 2007 12:57:21 -0000
@@ -48,6 +48,7 @@ function tracker_page($uid = 0) {
     $result = pager_query($sql, 25, 0, $sql_count);
   }
 
+  $latest = 0;
   $rows = array();
   while ($node = db_fetch_object($result)) {
     // Determine the number of comments:
@@ -68,12 +69,16 @@ function tracker_page($uid = 0) {
       array('class' => 'replies', 'data' => $comments),
       t('!time ago', array('!time' => format_interval(time() - $node->last_updated)))
     );
+
+    $latest = ($node->last_updated > $latest) ? $node->last_updated : $latest;
   }
 
   if (!$rows) {
     $rows[] = array(array('data' => t('No posts available.'), 'colspan' => '5'));
   }
 
+  drupal_set_page_last_modified($latest);
+
   $header = array(t('Type'), t('Post'), t('Author'), t('Replies'), t('Last updated'));
 
   $output = '<div id="tracker">';
