public function DynamicPageCacheSubscriber::onRouteMatch in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php \Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber::onRouteMatch()
Sets a response in case of a Dynamic Page Cache hit.
Parameters
\Symfony\Component\HttpKernel\Event\GetResponseEvent $event: The event to process.
File
- core/
modules/ dynamic_page_cache/ src/ EventSubscriber/ DynamicPageCacheSubscriber.php, line 131 - Contains \Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber.
Class
- DynamicPageCacheSubscriber
- Returns cached responses as early and avoiding as much work as possible.
Namespace
Drupal\dynamic_page_cache\EventSubscriberCode
public function onRouteMatch(GetResponseEvent $event) {
// Don't cache the response if the Dynamic Page Cache request policies are
// not met. Store the result in a request attribute, so that onResponse()
// does not have to redo the request policy check.
$request = $event
->getRequest();
$request_policy_result = $this->requestPolicy
->check($request);
$request->attributes
->set(self::ATTRIBUTE_REQUEST_POLICY_RESULT, $request_policy_result);
if ($request_policy_result === RequestPolicyInterface::DENY) {
return;
}
// Sets the response for the current route, if cached.
$cached = $this->renderCache
->get($this->dynamicPageCacheRedirectRenderArray);
if ($cached) {
$response = $this
->renderArrayToResponse($cached);
$response->headers
->set(self::HEADER, 'HIT');
$event
->setResponse($response);
}
}