function page_set_cache

You are here

4.6 bootstrap.inc page_set_cache()
4.7 common.inc page_set_cache()
5 common.inc page_set_cache()
6 common.inc page_set_cache()

Store the current page in the cache.

If page_compression is enabled, a gzipped version of the page is stored in the cache to avoid compressing the output on each request. The cache entry is unzipped in the relatively rare event that the page is requested by a client without gzip support.

Page compression requires the PHP zlib extension (http://php.net/manual/en/ref.zlib.php).

See also

drupal_page_header

1 call to page_set_cache()
drupal_page_footer in includes/common.inc
Perform end-of-request tasks.

File

includes/common.inc, line 2752
Common functions that many Drupal modules will need to reference.

Code

function page_set_cache() {
  global $user, $base_root;

  if (!$user->uid && $_SERVER['REQUEST_METHOD'] == 'GET' && page_get_cache(TRUE)) {
    // This will fail in some cases, see page_get_cache() for the explanation.
    if ($data = ob_get_contents()) {
      if (variable_get('page_compression', TRUE) && extension_loaded('zlib')) {
        $data = gzencode($data, 9, FORCE_GZIP);
      }
      ob_end_flush();
      cache_set($base_root . request_uri(), $data, 'cache_page', CACHE_TEMPORARY, drupal_get_headers());
    }
  }
}