.../src/EventSubscriber/SmartCacheSubscriber.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/modules/smart_cache/src/EventSubscriber/SmartCacheSubscriber.php b/core/modules/smart_cache/src/EventSubscriber/SmartCacheSubscriber.php index 2639134..384d889 100644 --- a/core/modules/smart_cache/src/EventSubscriber/SmartCacheSubscriber.php +++ b/core/modules/smart_cache/src/EventSubscriber/SmartCacheSubscriber.php @@ -140,13 +140,14 @@ public function onRouteMatch(GetResponseEvent $event) { // Get the contexts by which the current route's response must be varied. $cid = implode(':', $this->cacheContextsManager->convertTokensToKeys(['route'])->getKeys()); - $cache_contexts_for_route = $this->smartContextsCache->get($cid); + $cached = $this->smartContextsCache->get($cid); + $cache_contexts_for_route = ($cached !== FALSE) ? $cached->data : NULL; $request->attributes->set(self::ATTRIBUTE_CACHE_CONTEXTS_FOR_ROUTE_CID, $cid); $request->attributes->set(self::ATTRIBUTE_CACHE_CONTEXTS_FOR_ROUTE, $cache_contexts_for_route); // Get & set the cached HTML response for the current route, if any. - if ($cache_contexts_for_route !== FALSE) { - $cid = implode(':', $this->cacheContextsManager->convertTokensToKeys($cache_contexts_for_route->data)->getKeys()); + if (is_array($cache_contexts_for_route)) { + $cid = implode(':', $this->cacheContextsManager->convertTokensToKeys($cache_contexts_for_route)->getKeys()); $cached_html = $this->smartHtmlCache->get($cid); if ($cached_html !== FALSE) { $response = $cached_html->data; @@ -218,8 +219,7 @@ public function onResponse(FilterResponseEvent $event) { $this->normalizeCacheability($html_cacheability); // Get the contexts by which the current route's response must be varied. - $cache_contexts_for_route = $request->attributes->get(self::ATTRIBUTE_CACHE_CONTEXTS_FOR_ROUTE); - $stored_cache_contexts = ($cache_contexts_for_route !== FALSE) ? $cache_contexts_for_route->data : NULL; + $stored_cache_contexts = $request->attributes->get(self::ATTRIBUTE_CACHE_CONTEXTS_FOR_ROUTE); // If the set of cache contexts is different, store the union of the // already stored cache contexts and the contexts for this request. @@ -265,6 +265,12 @@ protected function normalizeCacheability(CacheableMetadata $cacheability) { */ public static function getSubscribedEvents() { $events = []; + + // Run after AuthenticationSubscriber (necessary for the 'user' cache + // context) and MaintenanceModeSubscriber (SmartCache should not be polluted + // by maintenance mode-specific behavior), but before + // ContentControllerSubscriber (updates _controller, but that's pointless + // when SmartCache runs). $events[KernelEvents::REQUEST][] = ['onRouteMatch', 27]; // Run before HtmlResponseSubscriber::onRespond(), which has priority 0.