class PageCache implements HttpKernelInterface (View source)

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

Properties

protected HttpKernelInterface $httpKernel

The wrapped HTTP kernel.

protected CacheBackendInterface $cache

The cache bin.

protected RequestPolicyInterface $requestPolicy

A policy rule determining the cacheability of a request.

protected ResponsePolicyInterface $responsePolicy

A policy rule determining the cacheability of the response.

protected string $cid

The cache ID for the (master) request.

Methods

__construct(HttpKernelInterface $http_kernel, CacheBackendInterface $cache, RequestPolicyInterface $request_policy, ResponsePolicyInterface $response_policy)

Constructs a PageCache object.

Response
handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)

{@inheritdoc}

pass(Request $request, int $type = self::MASTER_REQUEST, bool $catch = TRUE)

Sidesteps the page cache and directly forwards a request to the backend.

lookup(Request $request, int $type = self::MASTER_REQUEST, bool $catch = TRUE)

Retrieves a response from the cache or fetches it from the backend.

fetch(Request $request, int $type = self::MASTER_REQUEST, bool $catch = TRUE)

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

storeResponse(Request $request, Response $response)

Stores a response in the page cache.

Response|false
get(Request $request, bool $allow_invalid = FALSE)

Returns a response object from the page cache.

set(Request $request, Response $response, int $expire, array $tags)

Stores a response object in the page cache.

string
getCacheId(Request $request)

Gets the page cache ID for this request.

Details

__construct(HttpKernelInterface $http_kernel, CacheBackendInterface $cache, RequestPolicyInterface $request_policy, ResponsePolicyInterface $response_policy)

Constructs a PageCache object.

Parameters

HttpKernelInterface $http_kernel

The decorated kernel.

CacheBackendInterface $cache

The cache bin.

RequestPolicyInterface $request_policy

A policy rule determining the cacheability of a request.

ResponsePolicyInterface $response_policy

A policy rule determining the cacheability of the response.

Response handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)

{@inheritdoc}

Parameters

Request $request
$type
$catch

Return Value

Response

protected pass(Request $request, int $type = self::MASTER_REQUEST, bool $catch = TRUE)

Sidesteps the page cache and directly forwards a request to the backend.

Parameters

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

protected lookup(Request $request, int $type = self::MASTER_REQUEST, bool $catch = TRUE)

Retrieves a response from the cache or fetches it from the backend.

Parameters

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

protected fetch(Request $request, int $type = self::MASTER_REQUEST, bool $catch = TRUE)

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

Parameters

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()

protected storeResponse(Request $request, Response $response)

Stores a response in the page cache.

Parameters

Request $request

A request object.

Response $response

A response object that should be stored in the page cache.

protected Response|false get(Request $request, bool $allow_invalid = FALSE)

Returns a response object from the page cache.

Parameters

Request $request

A request object.

bool $allow_invalid

(optional) If TRUE, a cache item may be returned even if it is expired or has been invalidated. Such items may sometimes be preferred, if the alternative is recalculating the value stored in the cache, especially if another concurrent request is already recalculating the same value. The "valid" property of the returned object indicates whether the item is valid or not. Defaults to FALSE.

Return Value

Response|false

The cached response or FALSE on failure.

protected set(Request $request, Response $response, int $expire, array $tags)

Stores a response object in the page cache.

Parameters

Request $request

A request object.

Response $response

The response to store in the cache.

int $expire

One of the following values:

  • CacheBackendInterface::CACHE_PERMANENT: Indicates that the item should not be removed unless it is deleted explicitly.
  • A Unix timestamp: Indicates that the item will be considered invalid after this time, i.e. it will not be returned by get() unless $allow_invalid has been set to TRUE. When the item has expired, it may be permanently deleted by the garbage collector at any time.
array $tags

An array of tags to be stored with the cache item. These should normally identify objects used to build the cache item, which should trigger cache invalidation when updated. For example if a cached item represents a node, both the node ID and the author's user ID might be passed in as tags. For example array('node' => array(123), 'user' => array(92)).

protected string getCacheId(Request $request)

Gets the page cache ID for this request.

Parameters

Request $request

A request object.

Return Value

string

The cache ID for this request.