diff --git a/core/modules/dynamic_page_cache/dynamic_page_cache.module b/core/modules/dynamic_page_cache/dynamic_page_cache.module index dab03ed187258bb14b048aa43aaf9a8a7cdc9b1b..67d61316bd033ce311f8bb9735c9142a47da9932 100644 --- a/core/modules/dynamic_page_cache/dynamic_page_cache.module +++ b/core/modules/dynamic_page_cache/dynamic_page_cache.module @@ -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>'; diff --git a/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php b/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php index c0c339979446807b454b3fa4d72f944bcb53a6a9..103b303186be16a27350b3b5cd6348c7dffa70a3 100644 --- a/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php +++ b/core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php @@ -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. diff --git a/core/modules/dynamic_page_cache/tests/dynamic_page_cache_test/src/DynamicPageCacheTestController.php b/core/modules/dynamic_page_cache/tests/dynamic_page_cache_test/src/DynamicPageCacheTestController.php index 4371a29b02cff00191bf16d8105db54c22a88031..b11984e5eb5e0ec35d1534a62567d5a8225de796 100644 --- a/core/modules/dynamic_page_cache/tests/dynamic_page_cache_test/src/DynamicPageCacheTestController.php +++ b/core/modules/dynamic_page_cache/tests/dynamic_page_cache_test/src/DynamicPageCacheTestController.php @@ -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.