Returns cached responses as early and avoiding as much work as possible.
Dynamic Page Cache is able to cache so much because it utilizes cache contexts: the cache contexts that are present capture the variations of every component of the page. That, combined with the fact that cacheability metadata is bubbled, means that the cache contexts at the page level represent the complete set of contexts that the page varies by.
The reason Dynamic Page Cache is implemented as two event subscribers (a late REQUEST subscriber immediately after routing for cache hits, and an early RESPONSE subscriber for cache misses) is because many cache contexts can only be evaluated after routing. (Examples: 'user', 'user.permissions', 'route' …) Consequently, it is impossible to implement Dynamic Page Cache as a kernel middleware that simply caches per URL.
Hierarchy
- class \Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber implements EventSubscriberInterface
See also
\Drupal\Core\Render\MainContent\HtmlRenderer
\Drupal\Core\Cache\CacheableResponseInterface
File
- core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php, line 35
Namespace
Drupal\dynamic_page_cache\EventSubscriber
Members
Name | Modifiers | Type | Description |
---|---|---|---|
DynamicPageCacheSubscriber::$dynamicPageCacheRedirectRenderArray | protected | property | Dynamic Page Cache's redirect render array. |
DynamicPageCacheSubscriber::$renderCache | protected | property | The render cache. |
DynamicPageCacheSubscriber::$rendererConfig | protected | property | The renderer configuration array. |
DynamicPageCacheSubscriber::$requestPolicy | protected | property | A request policy rule determining the cacheability of a response. |
DynamicPageCacheSubscriber::$requestPolicyResults | protected | property | Internal cache of request policy results. |
DynamicPageCacheSubscriber::$responsePolicy | protected | property | A response policy rule determining the cacheability of the response. |
DynamicPageCacheSubscriber::getSubscribedEvents | public static | function | Returns an array of event names this subscriber wants to listen to. Overrides EventSubscriberInterface::getSubscribedEvents |
DynamicPageCacheSubscriber::HEADER | constant | Name of Dynamic Page Cache's response header. | |
DynamicPageCacheSubscriber::onResponse | public | function | Stores a response in case of a Dynamic Page Cache miss, if cacheable. |
DynamicPageCacheSubscriber::onRouteMatch | public | function | Sets a response in case of a Dynamic Page Cache hit. |
DynamicPageCacheSubscriber::renderArrayToResponse | protected | function | Gets the embedded Response object in a render array. |
DynamicPageCacheSubscriber::responseToRenderArray | protected | function | Embeds a Response object in a render array so that RenderCache can cache it. |
DynamicPageCacheSubscriber::shouldCacheResponse | protected | function | Whether the given response should be cached by Dynamic Page Cache. |
DynamicPageCacheSubscriber::__construct | public | function | Constructs a new DynamicPageCacheSubscriber object. |
Please login to continue.