Commit 04d331c6 authored by alexpott's avatar alexpott

Issue #2565455 by borisson_, Wim Leers: Follow-up for #2429617: small improvements

parent ede4d4ac
......@@ -18,7 +18,7 @@ function dynamic_page_cache_help($route_name, RouteMatchInterface $route_match)
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Speeding up your site') . '</dt>';
$output .= '<dd>' . t('Pages are cached the first time they are requested if they are suitable from caching, then the cached version is served for all later requests. Dynamic content is handled automatically so that both cache correctness and hit ratio is maintained.') . '</dd>';
$output .= '<dd>' . t('Pages which are suitable for caching are cached the first time they are requested, then the cached version is served for all later requests. Dynamic content is handled automatically so that both cache correctness and hit ratio is maintained.') . '</dd>';
$output .= '<dd>' . t('The module requires no configuration. Every part of the page contains metadata that allows Dynamic Page Cache to figure this out on its own.') . '</dd>';
$output .= '</dl>';
......
......@@ -22,7 +22,7 @@
/**
* Returns cached responses as early and avoiding as much work as possible.
*
* Dynamic Page Cache is able to cache so much because it exploits cache
* 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
......@@ -159,7 +159,8 @@ public function onResponse(FilterResponseEvent $event) {
// Dynamic Page Cache only works with cacheable responses. It does not work
// with plain Response objects. (Dynamic Page Cache needs to be able to
// access and modify the cacheability metadata associated with the response.)
// access and modify the cacheability metadata associated with the
// response.)
if (!$response instanceof CacheableResponseInterface) {
return;
}
......@@ -221,7 +222,7 @@ public function onResponse(FilterResponseEvent $event) {
* bubbling to the response level: while rendering, the Renderer checks every
* subtree to see if meets the auto-placeholdering conditions. If it does, it
* is automatically placeholdered, and consequently the cacheability metadata
* of the placeholdered content does not bubble up to the response level.
* of the placeholdered content does not bubble up to the response level.
*
* @param \Drupal\Core\Cache\CacheableResponseInterface
* The response whose cacheability to analyze.
......@@ -313,10 +314,10 @@ public static function getSubscribedEvents() {
$events = [];
// Run after AuthenticationSubscriber (necessary for the 'user' cache
// context) and MaintenanceModeSubscriber (Dynamic Page Cache should not be
// polluted by maintenance mode-specific behavior), but before
// ContentControllerSubscriber (updates _controller, but that is a no-op
// when Dynamic Page Cache runs).
// context; priority 300) and MaintenanceModeSubscriber (Dynamic Page Cache
// should not be polluted by maintenance mode-specific behavior; priority
// 30), but before ContentControllerSubscriber (updates _controller, but
// that is a no-op when Dynamic Page Cache runs; priority 25).
$events[KernelEvents::REQUEST][] = ['onRouteMatch', 27];
// Run before HtmlResponseSubscriber::onRespond(), which has priority 0.
......
......@@ -9,7 +9,9 @@
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Cache\CacheableResponse;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\user\Entity\User;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
......@@ -17,6 +19,8 @@
*/
class DynamicPageCacheTestController {
use StringTranslationTrait;
/**
* A route returning a Response object.
*
......@@ -57,15 +61,18 @@ public function html() {
/**
* A route returning a render array (with cache contexts, so cacheable).
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
*
* @return array
* A render array.
*
* @see html()
*/
public function htmlWithCacheContexts() {
public function htmlWithCacheContexts(Request $request) {
$build = $this->html();
$build['dynamic_part'] = [
'#markup' => SafeMarkup::format('Hello there, %animal.', ['%animal' => \Drupal::requestStack()->getCurrentRequest()->query->get('animal')]),
'#markup' => $this->t('Hello there, %animal.', ['%animal' => $request->query->get('animal')]),
'#cache' => [
'contexts' => [
'url.query_args:animal',
......@@ -105,7 +112,7 @@ public function htmlUncacheableMaxAge() {
public function htmlUncacheableContexts() {
$build = $this->html();
$build['very_dynamic_part'] = [
'#markup' => 'Drupal cannot handle the awesomeness of llamas.',
'#markup' => $this->t('@username cannot handle the awesomeness of llamas.', ['@username' => \Drupal::currentUser()->getDisplayName()]),
'#cache' => [
'contexts' => [
'user',
......@@ -116,7 +123,7 @@ public function htmlUncacheableContexts() {
}
/**
* A route returning a render array (with max-age=0, so uncacheable)
* A route returning a render array (with a cache tag preventing caching).
*
* @return array
* A render array.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment