How does Drupal avoid saving message information in the page cache?

Source: Internet
Author: User
Tags php cli drupal

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.