summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-09-28 00:19:44 +0200
committerAlex Pott2015-09-28 00:19:44 +0200
commit04d331c6ea8d9de5804b6f3a12d85c33b0fd89e2 (patch)
tree73de76725238c061aa05c1e8e511c44197e77482
parentede4d4ace0c6e32e6dbfc586947c715dd5aca36d (diff)
Issue #2565455 by borisson_, Wim Leers: Follow-up for #2429617: small improvements
-rw-r--r--core/modules/dynamic_page_cache/dynamic_page_cache.module2
-rw-r--r--core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php15
-rw-r--r--core/modules/dynamic_page_cache/tests/dynamic_page_cache_test/src/DynamicPageCacheTestController.php15
3 files changed, 20 insertions, 12 deletions
diff --git a/core/modules/dynamic_page_cache/dynamic_page_cache.module b/core/modules/dynamic_page_cache/dynamic_page_cache.module
index dab03ed..67d6131 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 c0c3399..103b303 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 @@ use Symfony\Component\HttpKernel\KernelEvents;
/**
* 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 @@ class DynamicPageCacheSubscriber implements EventSubscriberInterface {
// 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 @@ class DynamicPageCacheSubscriber implements EventSubscriberInterface {
* 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 @@ class DynamicPageCacheSubscriber implements EventSubscriberInterface {
$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 4371a29..b11984e 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 @@ namespace Drupal\dynamic_page_cache_test;
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 @@ use Symfony\Component\HttpFoundation\Response;
*/
class DynamicPageCacheTestController {
+ use StringTranslationTrait;
+
/**
* A route returning a Response object.
*
@@ -57,15 +61,18 @@ class DynamicPageCacheTestController {
/**
* 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 @@ class DynamicPageCacheTestController {
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 @@ class DynamicPageCacheTestController {
}
/**
- * 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.