Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. PageCache.php

function PageCache::handle

Overrides HttpKernelInterface::handle

File

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

Class

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

Namespace

Drupal\page_cache\StackMiddleware

Code

public function handle(Request $request, $type = self::MAIN_REQUEST, $catch = TRUE) : Response {
    // Only allow page caching on master request.
    if ($type === static::MAIN_REQUEST && $this->requestPolicy
        ->check($request) === RequestPolicyInterface::ALLOW) {
        $response = $this->lookup($request, $type, $catch);
    }
    else {
        $response = $this->pass($request, $type, $catch);
        // Don't indicate non-cacheability on responses to uncacheable requests.
        // @see https://tools.ietf.org/html/rfc7231#section-4.2.3
        if ($request->isMethodCacheable()) {
            $response->headers
                ->set(static::HEADER, 'UNCACHEABLE (request policy)');
        }
    }
    return $response;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal