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. 8.9.x core/modules/page_cache/src/StackMiddleware/PageCache.php \Drupal\page_cache\StackMiddleware\PageCache::fetch()
  3. 10 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.

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

Return value

\Symfony\Component\HttpFoundation\Response A response object.

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

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