function PageCache::fetch

Same name in other branches
  1. 9 core/modules/page_cache/src/StackMiddleware/PageCache.php \Drupal\page_cache\StackMiddleware\PageCache::fetch()
  2. 10 core/modules/page_cache/src/StackMiddleware/PageCache.php \Drupal\page_cache\StackMiddleware\PageCache::fetch()
  3. 11.x 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::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)

bool $catch: Whether to catch exceptions or not

See also

drupal_page_header()

1 call to PageCache::fetch()
PageCache::lookup in core/modules/page_cache/src/StackMiddleware/PageCache.php
Retrieves a response from the cache or fetches it from the backend.

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::MASTER_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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.