page_set_cache

Versions
4.6 – 6
page_set_cache()

Store the current page in the cache.

We try to store a gzipped version of the cache. This requires the PHP zlib extension (http://php.net/manual/en/ref.zlib.php). Presence of the extension is checked by testing for the function gzencode. There are two compression algorithms: gzip and deflate. The majority of all modern browsers support gzip or both of them. We thus only deal with the gzip variant and unzip the cache in case the browser does not accept gzip encoding.

See also

drupal_page_header

Code

includes/common.inc, line 2628

<?php
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()) {
      $cache = TRUE;
      if (variable_get('page_compression', TRUE) && function_exists('gzencode')) {
        // We do not store the data in case the zlib mode is deflate.
        // This should be rarely happening.
        if (zlib_get_coding_type() == 'deflate') {
          $cache = FALSE;
        }
        else if (zlib_get_coding_type() == FALSE) {
          $data = gzencode($data, 9, FORCE_GZIP);
        }
        // The remaining case is 'gzip' which means the data is
        // already compressed and nothing left to do but to store it.
      }
      ob_end_flush();
      if ($cache && $data) {
        cache_set($base_root . request_uri(), $data, 'cache_page', CACHE_TEMPORARY, drupal_get_headers());
      }
    }
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.