예제 #1
1
 public function serveCachedPage()
 {
     $cache_enabled = $this->getCacheMode();
     // If there is no session cookie and cache is enabled (or forced), try
     // to serve a cached page.
     if (!isset($_COOKIE[session_name()]) && $cache_enabled) {
         global $user;
         // Make sure there is a user object because its timestamp will be
         // checked, hook_boot might check for anonymous user etc.
         $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)) {
             header('X-Drupal-Cache: HIT');
             // Restore the metadata cached with the page.
             $_GET['q'] = $cache->data['path'];
             drupal_set_title($cache->data['title'], PASS_THROUGH);
             date_default_timezone_set(drupal_get_user_timezone());
             // If the skipping of the bootstrap hooks is not enforced, call
             // hook_boot.
             if (variable_get('page_cache_invoke_hooks', TRUE)) {
                 bootstrap_invoke_all('boot');
             }
             drupal_serve_page_from_cache($cache);
             // If the skipping of the bootstrap hooks is not enforced, call
             // hook_exit.
             if (variable_get('page_cache_invoke_hooks', TRUE)) {
                 bootstrap_invoke_all('exit');
             }
             // We are done.
             exit;
         } else {
             header('X-Drupal-Cache: MISS');
         }
     }
 }
 /**
  * {@inheritdoc}
  *
  * @todo Invoke proper request/response/terminate events.
  */
 public function handlePageCache(Request $request)
 {
     $this->boot();
     $this->initializeCookieGlobals($request);
     // Check for a cache mode force from settings.php.
     if (Settings::get('page_cache_without_database')) {
         $cache_enabled = TRUE;
     } else {
         $config = $this->getContainer()->get('config.factory')->get('system.performance');
         $cache_enabled = $config->get('cache.page.use_internal');
     }
     $request_policy = \Drupal::service('page_cache_request_policy');
     if ($cache_enabled && $request_policy->check($request) === RequestPolicyInterface::ALLOW) {
         // Get the page from the cache.
         $response = drupal_page_get_cache($request);
         // If there is a cached page, display it.
         if ($response) {
             $response->headers->set('X-Drupal-Cache', 'HIT');
             drupal_serve_page_from_cache($response, $request);
             // We are done.
             $response->prepare($request);
             $response->send();
             exit;
         }
     }
     return $this;
 }
예제 #3
0
 /**
  * {@inheritdoc}
  *
  * @todo Invoke proper request/response/terminate events.
  */
 public function handlePageCache(Request $request)
 {
     $this->boot();
     $this->initializeCookieGlobals($request);
     // Check for a cache mode force from settings.php.
     if (Settings::get('page_cache_without_database')) {
         $cache_enabled = TRUE;
     } else {
         $config = $this->getContainer()->get('config.factory')->get('system.performance');
         $cache_enabled = $config->get('cache.page.use_internal');
     }
     // 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 && drupal_page_is_cacheable()) {
         // Get the page from the cache.
         $response = drupal_page_get_cache($request);
         // If there is a cached page, display it.
         if ($response) {
             $response->headers->set('X-Drupal-Cache', 'HIT');
             drupal_serve_page_from_cache($response, $request);
             // We are done.
             $response->prepare($request);
             $response->send();
             exit;
         }
     }
     return $this;
 }