function _drupal_bootstrap_page_cache

Attempts to serve a page from the cache.

1 call to _drupal_bootstrap_page_cache()
drupal_bootstrap in drupal/core/includes/bootstrap.inc
Ensures Drupal is bootstrapped to the specified phase.

File

drupal/core/includes/bootstrap.inc, line 2029
Functions that need to be loaded on every Drupal request.

Code

function _drupal_bootstrap_page_cache() {
  global $user;

  // Allow specifying special cache handlers in settings.php, like
  // using memcached or files for storing cache information.
  require_once __DIR__ . '/cache.inc';
  foreach (variable_get('cache_backends', array()) as $include) {
    require_once DRUPAL_ROOT . '/' . $include;
  }

  // Check for a cache mode force from settings.php.
  if (settings()
    ->get('page_cache_without_database')) {
    $cache_enabled = TRUE;
  }
  else {
    drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES, FALSE);
    $config = config('system.performance');
    $cache_enabled = $config
      ->get('cache.page.use_internal');
  }

  // @todo this is *criminal*. but, necessary, until we fix bootstrap ordering.
  $request = Request::createFromGlobals();

  // If there is no session cookie and cache is enabled (or forced), try
  // to serve a cached page.
  if (!$request->cookies
    ->has(session_name()) && $cache_enabled) {

    // Make sure there is a user object because its timestamp will be checked.
    $user = drupal_anonymous_user();

    // Get the page from the cache.
    $cache = drupal_page_get_cache();

    // If there is a cached page, display it.
    if (is_object($cache)) {
      $response = new Response();
      $response->headers
        ->set('X-Drupal-Cache', 'HIT');

      // Restore the metadata cached with the page.
      _current_path($cache->data['path']);
      drupal_set_title($cache->data['title'], PASS_THROUGH);
      date_default_timezone_set(drupal_get_user_timezone());
      drupal_serve_page_from_cache($cache, $response, $request);

      // We are done.
      $response
        ->prepare($request);
      $response
        ->send();
      exit;
    }
    else {
      drupal_add_http_header('X-Drupal-Cache', 'MISS');
    }
  }
}