class MockedDynamicPageCacheSubscriber in Permissions by Term 8.2
Same name and namespace in other branches
- 8 modules/permissions_by_entity/tests/modules/pbt_entity_test/src/EventSubscriber/MockedDynamicPageCacheSubscriber.php \Drupal\pbt_entity_test\EventSubscriber\MockedDynamicPageCacheSubscriber
Mocked dynamic page cache subscriber.
Ensures the requests are cached.
Hierarchy
- class \Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\pbt_entity_test\EventSubscriber\MockedDynamicPageCacheSubscriber
Expanded class hierarchy of MockedDynamicPageCacheSubscriber
1 string reference to 'MockedDynamicPageCacheSubscriber'
- pbt_entity_test.services.yml in modules/
permissions_by_entity/ tests/ modules/ pbt_entity_test/ pbt_entity_test.services.yml - modules/permissions_by_entity/tests/modules/pbt_entity_test/pbt_entity_test.services.yml
1 service uses MockedDynamicPageCacheSubscriber
- mocked_dynamic_page_cache_subscriber in modules/
permissions_by_entity/ tests/ modules/ pbt_entity_test/ pbt_entity_test.services.yml - Drupal\pbt_entity_test\EventSubscriber\MockedDynamicPageCacheSubscriber
File
- modules/
permissions_by_entity/ tests/ modules/ pbt_entity_test/ src/ EventSubscriber/ MockedDynamicPageCacheSubscriber.php, line 14
Namespace
Drupal\pbt_entity_test\EventSubscriberView source
class MockedDynamicPageCacheSubscriber extends DynamicPageCacheSubscriber {
/**
* {@inheritdoc}
*/
public function onRouteMatch(GetResponseEvent $event) {
// 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);
}
}
/**
* {@inheritdoc}
*/
public function onResponse(FilterResponseEvent $event) {
$response = $event
->getResponse();
// Embed the response object in a render array so that RenderCache is able
// to cache it, handling cache redirection for us.
$response_as_render_array = $this
->responseToRenderArray($response);
$this->renderCache
->set($response_as_render_array, $this->dynamicPageCacheRedirectRenderArray);
// The response was generated, mark the response as a cache miss. The next
// time, it will be a cache hit.
$response->headers
->set(self::HEADER, 'MISS');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DynamicPageCacheSubscriber:: |
protected | property | Dynamic Page Cache's redirect render array. | |
DynamicPageCacheSubscriber:: |
protected | property | The render cache. | |
DynamicPageCacheSubscriber:: |
protected | property | The renderer configuration array. | |
DynamicPageCacheSubscriber:: |
protected | property | A request policy rule determining the cacheability of a response. | |
DynamicPageCacheSubscriber:: |
protected | property | Internal cache of request policy results. | |
DynamicPageCacheSubscriber:: |
protected | property | A response policy rule determining the cacheability of the response. | |
DynamicPageCacheSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
DynamicPageCacheSubscriber:: |
constant | Name of Dynamic Page Cache's response header. | ||
DynamicPageCacheSubscriber:: |
public | function | Sets a response in case of a Dynamic Page Cache hit. | |
DynamicPageCacheSubscriber:: |
protected | function | Gets the embedded Response object in a render array. | |
DynamicPageCacheSubscriber:: |
protected | function | Embeds a Response object in a render array so that RenderCache can cache it. | |
DynamicPageCacheSubscriber:: |
protected | function | Whether the given response should be cached by Dynamic Page Cache. | |
DynamicPageCacheSubscriber:: |
public | function | Constructs a new DynamicPageCacheSubscriber object. | |
MockedDynamicPageCacheSubscriber:: |
public | function |
Stores a response in case of a Dynamic Page Cache miss, if cacheable. Overrides DynamicPageCacheSubscriber:: |
|
MockedDynamicPageCacheSubscriber:: |
public | function |