core/core.services.yml | 2 +- .../Core/EventSubscriber/SmartCacheSubscriber.php | 18 +++++++++--------- .../Core/Render/MainContent/SmartCacheHtmlRenderer.php | 16 ++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/core/core.services.yml b/core/core.services.yml index 605693c..d5b7d75 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -891,7 +891,7 @@ services: arguments: [smart_cache_html] smart_cache_subscriber: class: Drupal\Core\EventSubscriber\SmartCacheSubscriber - arguments: ['@current_route_match', '@cache_contexts', '@cache.smart_cache_contexts', '@cache.smart_cache_html'] + arguments: ['@current_route_match', '@cache_contexts_manager', '@cache.smart_cache_contexts', '@cache.smart_cache_html'] tags: - { name: event_subscriber } diff --git a/core/lib/Drupal/Core/EventSubscriber/SmartCacheSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/SmartCacheSubscriber.php index 00d5972..51fde1b 100644 --- a/core/lib/Drupal/Core/EventSubscriber/SmartCacheSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/SmartCacheSubscriber.php @@ -8,7 +8,7 @@ namespace Drupal\Core\EventSubscriber; use Drupal\Core\Cache\CacheBackendInterface; -use Drupal\Core\Cache\CacheContexts; +use Drupal\Core\Cache\CacheContextsManager; use Drupal\Core\Routing\RouteMatchInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\GetResponseEvent; @@ -29,11 +29,11 @@ class SmartCacheSubscriber implements EventSubscriberInterface { protected $routeMatch; /** - * The cache contexts service. + * The cache contexts manager. * - * @var \Drupal\Core\Cache\CacheContexts + * @var \Drupal\Core\Cache\CacheContextsManager */ - protected $cacheContexts; + protected $cacheContextsManager; /** * The Smart Cache contexts cache bin. @@ -54,16 +54,16 @@ class SmartCacheSubscriber implements EventSubscriberInterface { * * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The current route match. - * @param \Drupal\Core\Cache\CacheContexts $cache_contexts + * @param \Drupal\Core\Cache\CacheContextsManager $cache_contexts_manager * The cache contexts service. * @param \Drupal\Core\Cache\CacheBackendInterface $contexts_cache * The Smart Cache contexts cache bin. * @param \Drupal\Core\Cache\CacheBackendInterface $html_cache * The Smart Cache #type => html render array cache bin. */ - public function __construct(RouteMatchInterface $route_match, CacheContexts $cache_contexts, CacheBackendInterface $contexts_cache, CacheBackendInterface $html_cache) { + public function __construct(RouteMatchInterface $route_match, CacheContextsManager $cache_contexts_manager, CacheBackendInterface $contexts_cache, CacheBackendInterface $html_cache) { $this->routeMatch = $route_match; - $this->cacheContexts = $cache_contexts; + $this->cacheContextsManager = $cache_contexts_manager; $this->smartContextsCache = $contexts_cache; $this->smartHtmlCache = $html_cache; } @@ -90,13 +90,13 @@ public function onRouteMatch(GetResponseEvent $event) { $this->routeMatch->getRouteName(); // Get the contexts by which the current route's response must be varied. - $cache_contexts = $this->smartContextsCache->get('smartcache:contexts:' . $this->cacheContexts->convertTokensToKeys(['route'])[0]); + $cache_contexts = $this->smartContextsCache->get('smartcache:contexts:' . $this->cacheContextsManager->convertTokensToKeys(['route'])[0]); // If we already know the contexts by which the current route's response // must be varied, check if a response already is cached for the current // request's values for those contexts, and if so, return early. if ($cache_contexts !== FALSE) { - $cid = 'smartcache:html_render_array:' . implode(':', $this->cacheContexts->convertTokensToKeys($cache_contexts->data)); + $cid = 'smartcache:html_render_array:' . implode(':', $this->cacheContextsManager->convertTokensToKeys($cache_contexts->data)); $cached_html = $this->smartHtmlCache->get($cid); if ($cached_html !== FALSE) { $html = $cached_html->data; diff --git a/core/lib/Drupal/Core/Render/MainContent/SmartCacheHtmlRenderer.php b/core/lib/Drupal/Core/Render/MainContent/SmartCacheHtmlRenderer.php index 610933a..f422b97 100644 --- a/core/lib/Drupal/Core/Render/MainContent/SmartCacheHtmlRenderer.php +++ b/core/lib/Drupal/Core/Render/MainContent/SmartCacheHtmlRenderer.php @@ -10,7 +10,7 @@ use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; -use Drupal\Core\Cache\CacheContexts; +use Drupal\Core\Cache\CacheContextsManager; use Drupal\Core\Controller\TitleResolverInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Render\Element; @@ -62,7 +62,7 @@ class SmartCacheHtmlRenderer extends HtmlRenderer { * The module handler. * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer service. - * @param \Drupal\Core\Cache\CacheContexts $cache_contexts + * @param \Drupal\Core\Cache\CacheContextsManager $cache_contexts_manager * The cache contexts service. * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The current route match. @@ -73,8 +73,8 @@ class SmartCacheHtmlRenderer extends HtmlRenderer { * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack * The request stack. */ - public function __construct(TitleResolverInterface $title_resolver, PluginManagerInterface $display_variant_manager, EventDispatcherInterface $event_dispatcher, ElementInfoManagerInterface $element_info_manager, ModuleHandlerInterface $module_handler, RendererInterface $renderer, CacheContexts $cache_contexts, RouteMatchInterface $route_match, CacheBackendInterface $contexts_cache, CacheBackendInterface $html_cache, RequestStack $request_stack) { - parent::__construct($title_resolver, $display_variant_manager, $event_dispatcher, $element_info_manager, $module_handler, $renderer, $cache_contexts); + public function __construct(TitleResolverInterface $title_resolver, PluginManagerInterface $display_variant_manager, EventDispatcherInterface $event_dispatcher, ElementInfoManagerInterface $element_info_manager, ModuleHandlerInterface $module_handler, RendererInterface $renderer, CacheContextsManager $cache_contexts_manager, RouteMatchInterface $route_match, CacheBackendInterface $contexts_cache, CacheBackendInterface $html_cache, RequestStack $request_stack) { + parent::__construct($title_resolver, $display_variant_manager, $event_dispatcher, $element_info_manager, $module_handler, $renderer, $cache_contexts_manager); $this->routeMatch = $route_match; $this->smartContextsCache = $contexts_cache; $this->smartHtmlCache = $html_cache; @@ -101,7 +101,7 @@ protected function finish(array $html) { $cacheable_html = $html; // Get the contexts by which the current route's response must be varied. - $contexts_cid = 'smartcache:contexts:' . $this->cacheContexts->convertTokensToKeys(['route'])[0]; + $contexts_cid = 'smartcache:contexts:' . $this->cacheContextsManager->convertTokensToKeys(['route'])[0]; $stored_cache_contexts = $this->smartContextsCache->get($contexts_cid); if ($stored_cache_contexts !== FALSE) { $stored_cache_contexts = $stored_cache_contexts->data; @@ -146,18 +146,18 @@ protected function finish(array $html) { // SmartCache only caches cacheable pages. if ($html_cache_max_age !== 0) { - $html_cache_contexts = $this->cacheContexts->optimizeTokens($html_cache_contexts); + $html_cache_contexts = $this->cacheContextsManager->optimizeTokens($html_cache_contexts); // If the set of cache contexts is different, store the union of the already // stored cache contexts and the contexts for this request. if ($html_cache_contexts !== $stored_cache_contexts) { if (is_array($stored_cache_contexts)) { - $html_cache_contexts = $this->cacheContexts->optimizeTokens(Cache::mergeContexts($html_cache_contexts, $stored_cache_contexts)); + $html_cache_contexts = $this->cacheContextsManager->optimizeTokens(Cache::mergeContexts($html_cache_contexts, $stored_cache_contexts)); } $this->smartContextsCache->set($contexts_cid, $html_cache_contexts); } // Finally, cache the #type => html render array by those contexts. - $cid = 'smartcache:html_render_array:' . implode(':', $this->cacheContexts->convertTokensToKeys($html_cache_contexts)); + $cid = 'smartcache:html_render_array:' . implode(':', $this->cacheContextsManager->convertTokensToKeys($html_cache_contexts)); $expire = ($html_cache_max_age === Cache::PERMANENT) ? Cache::PERMANENT : (int) $this->requestStack->getMasterRequest()->server->get('REQUEST_TIME') + $html_cache_max_age; $this->smartHtmlCache->set($cid, $cacheable_html, $expire, $html_cache_tags); }