core/lib/Drupal/Core/Form/FormBuilder.php | 1 + .../src/EventSubscriber/SmartCacheSubscriber.php | 9 +------ .../src/SmartCacheTestController.php | 31 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index cbdcaa7..b803be0 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -622,6 +622,7 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) { } // Mark every non-GET form as uncacheable. + // @todo Refine in https://www.drupal.org/node/2526472. if (!$form_state->isMethodType('get')) { $form['#cache']['max-age'] = 0; } diff --git a/core/modules/smart_cache/src/EventSubscriber/SmartCacheSubscriber.php b/core/modules/smart_cache/src/EventSubscriber/SmartCacheSubscriber.php index 384d889..056ea88 100644 --- a/core/modules/smart_cache/src/EventSubscriber/SmartCacheSubscriber.php +++ b/core/modules/smart_cache/src/EventSubscriber/SmartCacheSubscriber.php @@ -166,7 +166,7 @@ public function onRouteMatch(GetResponseEvent $event) { public function onResponse(FilterResponseEvent $event) { $response = $event->getResponse(); - // SmartCache only works with HTML responses that are actual HTMLResponse + // SmartCache only works with HTML responses that are actual HTMLResponse // objects, it does not work with plain Response objects that happen to // return HTML. (SmartCache needs to be able to access and modify the // cacheability metadata associated with the HTML response.) @@ -207,13 +207,6 @@ public function onResponse(FilterResponseEvent $event) { ->addCacheContexts(['route']) ->addCacheTags(['rendered']); - // @todo DEBUG DEBUG DEBUG PROFILING PROFILING PROFILING — Until only the - // truly uncacheable things set max-age = 0 (such as the search block and - // the breadcrumbs block, which currently set max-age = 0, even though it - // is perfectly possible to cache them), to see the performance boost this - // will bring, uncomment this line. -//$html_cacheability->setCacheMaxAge(Cache::PERMANENT); - // SmartCache only caches cacheable HTML responses, i.e. with a max-age > 0. if ($html_cacheability->getCacheMaxAge() !== 0) { $this->normalizeCacheability($html_cacheability); diff --git a/core/modules/smart_cache/tests/smart_cache_test/src/SmartCacheTestController.php b/core/modules/smart_cache/tests/smart_cache_test/src/SmartCacheTestController.php index 28bb937..177d5f5 100644 --- a/core/modules/smart_cache/tests/smart_cache_test/src/SmartCacheTestController.php +++ b/core/modules/smart_cache/tests/smart_cache_test/src/SmartCacheTestController.php @@ -10,12 +10,27 @@ use Drupal\Component\Utility\SafeMarkup; use Symfony\Component\HttpFoundation\Response; +/** + * Controller routines for smart_cache_test routes. + */ class SmartCacheTestController { + /** + * A route returning a Response object. + * + * @return \Symfony\Component\HttpFoundation\Response + * A Response object. + */ public function response() { return new Response('foobar'); } + /** + * A route returning a render array (without cache contexts, so cacheable). + * + * @return array + * A render array. + */ public function html() { return [ 'content' => [ @@ -24,6 +39,14 @@ public function html() { ]; } + /** + * A route returning a render array (with cache contexts, so cacheable). + * + * @return array + * A render array. + * + * @see html() + */ public function htmlWithCacheContexts() { $build = $this->html(); $build['dynamic_part'] = [ @@ -37,6 +60,14 @@ public function htmlWithCacheContexts() { return $build; } + /** + * A route returning a render array (with max-age=0, so uncacheable) + * + * @return array + * A render array. + * + * @see html() + */ public function htmlUncacheable() { $build = $this->html(); $build['very_dynamic_part'] = [