Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.836
diff -u -p -r1.836 common.inc
--- includes/common.inc	9 Dec 2008 11:09:26 -0000	1.836
+++ includes/common.inc	11 Dec 2008 04:43:39 -0000
@@ -1781,6 +1781,9 @@ function drupal_page_footer() {
 
   module_invoke_all('exit');
 
+  // Clear messages.
+  drupal_get_messages(NULL, TRUE);
+
   module_implements(MODULE_IMPLEMENTS_WRITE_CACHE);
   _registry_check_code(REGISTRY_WRITE_LOOKUP_CACHE);
 }
Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.455
diff -u -p -r1.455 theme.inc
--- includes/theme.inc	7 Dec 2008 09:32:58 -0000	1.455
+++ includes/theme.inc	11 Dec 2008 04:43:41 -0000
@@ -1112,7 +1112,7 @@ function theme_placeholder($text) {
  */
 function theme_status_messages($display = NULL) {
   $output = '';
-  foreach (drupal_get_messages($display) as $type => $messages) {
+  foreach (drupal_get_messages($display, FALSE) as $type => $messages) {
     $output .= "<div class=\"messages $type\">\n";
     if (count($messages) > 1) {
       $output .= " <ul>\n";
Index: modules/simpletest/tests/cache.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/cache.test,v
retrieving revision 1.3
diff -u -p -r1.3 cache.test
--- modules/simpletest/tests/cache.test	8 Dec 2008 21:41:54 -0000	1.3
+++ modules/simpletest/tests/cache.test	11 Dec 2008 04:43:42 -0000
@@ -101,6 +101,50 @@ class CacheTestCase extends DrupalWebTes
   }
 }
 
+/**
+ * Test page caching.
+ */
+class CachePageCase extends CacheTestCase {
+
+  function getInfo() {
+    return array(
+      'name' => t('Cache page test'),
+      'description' => t('Check caching of pages and pages with messages.'),
+      'group' => t('Cache'),
+    );
+  }
+
+  function setUp() {
+    parent::setUp('system_test');
+
+    $this->node = $this->drupalCreateNode(array('promote' => 1));
+    variable_set('cache', CACHE_NORMAL);
+  }
+
+  /**
+   * Test that pages with messages are not saved in the cache.
+   */
+  function testCacheMessages() {
+    // Make sure the page is not cached.
+    $cache = cache_get(url('', array('absolute' => TRUE)), 'cache_page');
+    $this->assertFalse($cache, t('Page is not cached.'));
+
+    // View the front page with a message on it.
+    variable_set('front_page_output', 1);
+    $this->drupalGet('');
+    $this->assertText(t('On front page.'), t('Message found.'));
+    $cache = cache_get(url('', array('absolute' => TRUE)), 'cache_page');
+    $this->assertFalse($cache, t('Page has not been cached.'));
+
+    // View the front page without a message on it.
+    variable_set('front_page_output', 0);
+    $this->drupalGet('');
+    $this->assertNoText(t('On front page.'), t('Message not found.'));
+    $cache = cache_get(url('', array('absolute' => TRUE)), 'cache_page');
+    $this->assertTrue($cache, t('Page has been cached.'));
+  }
+}
+
 class CacheSavingCase extends CacheTestCase {
   function getInfo() {
     return array(
@@ -224,4 +268,4 @@ class CacheClearCase extends CacheTestCa
                       || $this->checkCacheExists('test_cid_clear2', $this->default_value),
                       t('Two caches removed after clearing cid substring with wildcard true.'));
   }
-}
\ No newline at end of file
+}
