Code of the page_get_cache function:
function page_get_cache($status_only = FALSE) { static $status = FALSE; global $user, $base_root; if ($status_only) { return $status; } $cache = NULL; if (!$user->uid && $_SERVER[‘REQUEST_METHOD‘] == ‘GET‘ && count(drupal_set_message()) == 0 && $_SERVER[‘SERVER_SOFTWARE‘] !== ‘PHP CLI‘) { $cache = cache_get($base_root . request_uri(), ‘cache_page‘); if (empty($cache)) { ob_start(); $status = TRUE; } } return $cache;}
It can be seen that the cache is obtained only when the message is 0.
Let's take a look at the page_set_cache function, which stores the cache
1 function page_set_cache() { 2 global $user, $base_root; 3 4 if (!$user->uid && $_SERVER[‘REQUEST_METHOD‘] == ‘GET‘ && page_get_cache(TRUE)) { 5 // This will fail in some cases, see page_get_cache() for the explanation. 6 if ($data = ob_get_contents()) { 7 if (variable_get(‘page_compression‘, TRUE) && extension_loaded(‘zlib‘)) { 8 $data = gzencode($data, 9, FORCE_GZIP); 9 }10 ob_end_flush();11 cache_set($base_root . request_uri(), $data, ‘cache_page‘, CACHE_TEMPORARY, drupal_get_headers());12 }13 }14 }
There is a line of code page_get_cache (true) to determine whether the cache can be found. If it cannot be found, return true, and then the page will be cached. When drupal_set_message () is not empty, page_get_cache (true) always returns false. It can be seen that Drupal judges whether there is a message when obtaining the page cache and setting the page cache, the cache is set or the cache is obtained only when the message is empty.