--- includes/bootstrap.inc.1.330	2009-11-22 08:20:51.000000000 +0000
+++ includes/bootstrap.inc	2009-12-01 02:59:19.000000000 +0000
@@ -1569,30 +1569,41 @@ function _drupal_bootstrap_page_cache() 
     $cache_mode = variable_get('cache');
   }
   drupal_block_denied(ip_address());
-  // If there is no session cookie and cache is enabled (or forced), try
-  // to serve a cached page.
-  if (!isset($_COOKIE[session_name()]) && $cache_mode == CACHE_NORMAL) {
-    // Make sure there is a user object because it's timestamp will be
-    // checked, hook_boot might check for anonymous user etc.
-    $user = drupal_anonymous_user();
-    // Get the page from the cache.
-    $cache = drupal_page_get_cache();
-    // If there is a cached page, display it.
-    if (is_object($cache)) {
-      // If the skipping of the bootstrap hooks is not enforced, call
-      // hook_boot.
-      if (variable_get('page_cache_invoke_hooks', TRUE)) {
-        bootstrap_invoke_all('boot');
-      }
-      header('X-Drupal-Cache: HIT');
-      drupal_serve_page_from_cache($cache);
-      // If the skipping of the bootstrap hooks is not enforced, call
-      // hook_exit.
-      if (variable_get('page_cache_invoke_hooks', TRUE)) {
-        bootstrap_invoke_all('exit');
+  if ($cache_mode == CACHE_NORMAL) {
+    // Cache is enabled (or forced) - need to check for session cookie.
+    if (isset($_COOKIE[session_name()])) {
+      // The user has a session cookie - check the session and set the request
+      // to "not cacheable" if the conditions for serving a cached response
+      // are not met.
+      drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION, FALSE);
+    }
+    else {
+      // Make sure there is a user object because it's timestamp will be
+      // checked, hook_boot might check for anonymous user etc.
+      $user = drupal_anonymous_user();
+    }
+    if (!isset($_COOKIE[session_name()]) || variable_get('page_cache_with_anonymous_sessions', FALSE)) {
+      // Get the page from the cache. If the user has a session but the
+      // conditions for serving a cached response are not met then this will
+      // fail.
+      $cache = drupal_page_get_cache();
+      // If there is a cached page, display it.
+      if (is_object($cache)) {
+        // If the skipping of the bootstrap hooks is not enforced, call
+        // hook_boot.
+        if (variable_get('page_cache_invoke_hooks', TRUE)) {
+          bootstrap_invoke_all('boot');
+        }
+        header('X-Drupal-Cache: HIT');
+        drupal_serve_page_from_cache($cache);
+        // If the skipping of the bootstrap hooks is not enforced, call
+        // hook_exit.
+        if (variable_get('page_cache_invoke_hooks', TRUE)) {
+          bootstrap_invoke_all('exit');
+        }
+        // We are done.
+        exit;
       }
-      // We are done.
-      exit;
     }
   }
 }
--- includes/session.inc.1.73	2009-11-04 05:05:52.000000000 +0000
+++ includes/session.inc	2009-12-01 02:56:23.000000000 +0000
@@ -195,8 +195,20 @@ function drupal_session_initialize() {
     // anonymous users not use a session cookie unless something is stored in
     // $_SESSION. This allows HTTP proxies to cache anonymous pageviews.
     drupal_session_start();
-    if (!empty($user->uid) || !empty($_SESSION)) {
-      drupal_page_is_cacheable(FALSE);
+    if (variable_get('page_cache_with_anonymous_sessions', FALSE)) {
+      // The site is configured to allow the page cache to operate for
+      // anonymous users who have a session. Disable caching if user is logged
+      // in or there are messages to display from a previous page request.
+      if (!empty($user->uid) || count(drupal_get_messages(NULL, FALSE)) > 0) {
+        drupal_page_is_cacheable(FALSE);
+      }
+    }
+    else {
+      // Default case - disable caching if user is logged in or they have
+      // something stored in $_SESSION.
+      if (!empty($user->uid) || !empty($_SESSION)) {
+        drupal_page_is_cacheable(FALSE);
+      }
     }
   }
   else {
