You are here

protected function PageCache::fetch in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/page_cache/src/StackMiddleware/PageCache.php \Drupal\page_cache\StackMiddleware\PageCache::fetch()
  2. 9 core/modules/page_cache/src/StackMiddleware/PageCache.php \Drupal\page_cache\StackMiddleware\PageCache::fetch()

Fetches a response from the backend and stores it in the cache.

@returns \Symfony\Component\HttpFoundation\Response $response A response object.

Parameters

\Symfony\Component\HttpFoundation\Request $request: A request object.

int $type: The type of the request (one of HttpKernelInterface::MAIN_REQUEST or HttpKernelInterface::SUB_REQUEST)

bool $catch: Whether to catch exceptions or not

See also

drupal_page_header()

File

core/modules/page_cache/src/StackMiddleware/PageCache.php, line 189

Class

PageCache
Executes the page caching before the main kernel takes over the request.

Namespace

Drupal\page_cache\StackMiddleware

Code

protected function fetch(Request $request, $type = self::MAIN_REQUEST, $catch = TRUE) {

  /** @var \Symfony\Component\HttpFoundation\Response $response */
  $response = $this->httpKernel
    ->handle($request, $type, $catch);

  // Only set the 'X-Drupal-Cache' header if caching is allowed for this
  // response.
  if ($this
    ->storeResponse($request, $response)) {
    $response->headers
      ->set('X-Drupal-Cache', 'MISS');
  }
  return $response;
}