函数page_get_cache代码:
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; }
可见,当message为0时,才会从cache中获取缓存。
再来看看page_set_cache函数,该函数负责保存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 }
其中有行代码page_get_cache(TRUE),来判断是否能找到cache,如果不能找到,返回TRUE,这时候才会做页面的缓存。而当drupal_set_message()不为空时,page_get_cache(TRUE)始终都会返回FALSE,可见drupal在获取页面缓存和设置页面缓存时,都对是否有message做了判断,只有message为空时才会设置缓存、或者获取缓存。
Drupal是如何避免页面缓存保存Message信息的
时间: 2024-10-10 10:10:13