diff -u b/core/lib/Drupal/Core/Cache/Context/CacheContextInterface.php b/core/lib/Drupal/Core/Cache/Context/CacheContextInterface.php --- b/core/lib/Drupal/Core/Cache/Context/CacheContextInterface.php +++ b/core/lib/Drupal/Core/Cache/Context/CacheContextInterface.php @@ -11,7 +11,7 @@ /** * Provides an interface for defining a cache context service. */ -interface CacheContextInterface extends CacheableDependencyInterface { +interface CacheContextInterface { /** * Returns the label of the cache context. @@ -22,13 +22,13 @@ public static function getLabel(); /** - * Returns the string representation of the cache context. + * Returns a object containing cache context and its cacheability metadata. * * A cache context service's name is used as a token (placeholder) cache key, * and is then replaced with the string returned by this method. * - * @return string - * The string representation of the cache context. + * @return \Drupal\Core\Cache\Context\CacheContextValue. + * A object containing cache context and its cacheability metadata. */ public function getContext(); diff -u b/core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php b/core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php --- b/core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php +++ b/core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php @@ -100,8 +100,8 @@ * @param string[] $context_tokens * An array of cache context tokens. * - * @return \Drupal\Core\Cache\Context\CacheContextInterface[] - * The array of corresponding cache keys. + * @return \Drupal\Core\Cache\Context\CacheContextValue[] + * The array of corresponding cache keys with their cacheability metadata. * * @throws \InvalidArgumentException */ @@ -114,13 +114,9 @@ if (!in_array($context_id, $this->contexts)) { throw new \InvalidArgumentException(SafeMarkup::format('"@context" is not a valid cache context ID.', ['@context' => $context_id])); } - $service = $this->getService($context_id); - // @todo find a better way to do this. - if ($service instanceof CalculatedCacheContextInterface) { - $service->setParameter($parameter); - } - $cache_contexts[] = $service; + $cache_contexts[] = $this->getService($context_id)->getContext($parameter); } + return $cache_contexts; } diff -u b/core/lib/Drupal/Core/Cache/Context/CalculatedCacheContextInterface.php b/core/lib/Drupal/Core/Cache/Context/CalculatedCacheContextInterface.php --- b/core/lib/Drupal/Core/Cache/Context/CalculatedCacheContextInterface.php +++ b/core/lib/Drupal/Core/Cache/Context/CalculatedCacheContextInterface.php @@ -23,7 +23,7 @@ public static function getLabel(); /** - * Returns the string representation of the cache context. + * Returns the cache context with its cacheability metadata.. * * A cache context service's name is used as a token (placeholder) cache key, * and is then replaced with the string returned by this method. @@ -33,13 +33,9 @@ * - * @return string - * The string representation of the cache context. When $parameter is NULL, - * a value representing all possible parameters must be generated. + * @return \Drupal\Core\Cache\Context\CacheContextValue. + * A object containing cache context and its cacheability metadata. When + * $parameter is NULL, a value representing all possible parameters must be + * generated. */ public function getContext($parameter = NULL); - /** - * @todo find better way to do this. - */ - public function setParameter($parameter); - } diff -u b/core/lib/Drupal/Core/Cache/Context/CookiesCacheContext.php b/core/lib/Drupal/Core/Cache/Context/CookiesCacheContext.php --- b/core/lib/Drupal/Core/Cache/Context/CookiesCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/CookiesCacheContext.php @@ -12,8 +12,6 @@ */ class CookiesCacheContext extends RequestStackCacheContextBase implements CalculatedCacheContextInterface { - use DefaultCacheContextTrait; - /** * {@inheritdoc} */ @@ -26,10 +24,10 @@ */ public function getContext($cookie = NULL) { if ($cookie === NULL) { - return $this->requestStack->getCurrentRequest()->cookies->all(); + return new CacheContextValue($this->requestStack->getCurrentRequest()->cookies->all()); } else { - return $this->requestStack->getCurrentRequest()->cookies->get($cookie); + return new CacheContextValue($this->requestStack->getCurrentRequest()->cookies->get($cookie)); } } reverted: --- b/core/lib/Drupal/Core/Cache/Context/DefaultCacheContextTrait.php +++ /dev/null @@ -1,68 +0,0 @@ -contexts; - } - - /** - * {@inheritdoc} - */ - public function getCacheTags() { - return $this->tags; - } - - /** - * {@inheritdoc} - */ - public function getCacheMaxAge() { - return $this->maxAge; - } - - /** - * Add cache context to the end of cache context list. - * - * @param string $context - * - * @return $this - */ - public function addCacheContext($context) { - $this->contexts[] = $context; - return $this; - } -} \ No newline at end of file diff -u b/core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php b/core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php --- b/core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php @@ -12,8 +12,6 @@ */ class HeadersCacheContext extends RequestStackCacheContextBase implements CalculatedCacheContextInterface { - use DefaultCacheContextTrait; - /** * {@inheritdoc} */ @@ -26,10 +24,10 @@ */ public function getContext($header = NULL) { if ($header === NULL) { - return $this->requestStack->getCurrentRequest()->headers->all(); + return new CacheContextValue($this->requestStack->getCurrentRequest()->headers->all()); } else { - return $this->requestStack->getCurrentRequest()->headers->get($header); + return new CacheContextValue($this->requestStack->getCurrentRequest()->headers->get($header)); } } diff -u b/core/lib/Drupal/Core/Cache/Context/IpCacheContext.php b/core/lib/Drupal/Core/Cache/Context/IpCacheContext.php --- b/core/lib/Drupal/Core/Cache/Context/IpCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/IpCacheContext.php @@ -12,8 +12,6 @@ */ class IpCacheContext extends RequestStackCacheContextBase { - use DefaultCacheContextTrait; - /** * {@inheritdoc} */ @@ -25,7 +23,7 @@ * {@inheritdoc} */ public function getContext() { - return $this->requestStack->getCurrentRequest()->getClientIp(); + return new CacheContextValue($this->requestStack->getCurrentRequest()->getClientIp()); } } diff -u b/core/lib/Drupal/Core/Cache/Context/IsSuperUserCacheContext.php b/core/lib/Drupal/Core/Cache/Context/IsSuperUserCacheContext.php --- b/core/lib/Drupal/Core/Cache/Context/IsSuperUserCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/IsSuperUserCacheContext.php @@ -12,8 +12,6 @@ */ class IsSuperUserCacheContext extends UserCacheContext { - use DefaultCacheContextTrait; - /** * {@inheritdoc} */ @@ -25,7 +23,7 @@ * {@inheritdoc} */ public function getContext() { - return ((int) $this->user->id()) === 1 ? '1' : '0'; + return new CacheContextValue(((int) $this->user->id()) === 1 ? '1' : '0'); } } diff -u b/core/lib/Drupal/Core/Cache/Context/LanguagesCacheContext.php b/core/lib/Drupal/Core/Cache/Context/LanguagesCacheContext.php --- b/core/lib/Drupal/Core/Cache/Context/LanguagesCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/LanguagesCacheContext.php @@ -14,13 +14,6 @@ */ class LanguagesCacheContext implements CalculatedCacheContextInterface { - use DefaultCacheContextTrait; - - /** - * @todo remove this? - */ - protected $language = NULL; - /** * The language manager. * @@ -60,11 +53,6 @@ * In case an invalid language type is specified. */ public function getContext($type = NULL) { - // @todo remove this? - if ($type === NULL) { - $type = $this->language; - } - if ($type === NULL) { $context_parts = array(); if ($this->languageManager->isMultilingual()) { @@ -77,20 +65,13 @@ } - return implode(',', $context_parts); + return new CacheContextValue(implode(',', $context_parts)); } else { $language_types = $this->languageManager->getDefinedLanguageTypesInfo(); if (!isset($language_types[$type])) { throw new \RuntimeException(sprintf('The language type "%s" is invalid.', $type)); } - return $this->languageManager->getCurrentLanguage($type)->getId(); + return new CacheContextValue($this->languageManager->getCurrentLanguage($type)->getId()); } } - /** - * @todo remove this? - */ - public function setParameter($parameter) { - $this->language = $parameter; - } - } diff -u b/core/lib/Drupal/Core/Cache/Context/MenuActiveTrailsCacheContext.php b/core/lib/Drupal/Core/Cache/Context/MenuActiveTrailsCacheContext.php --- b/core/lib/Drupal/Core/Cache/Context/MenuActiveTrailsCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/MenuActiveTrailsCacheContext.php @@ -17,13 +17,6 @@ */ class MenuActiveTrailsCacheContext extends ContainerAware implements CalculatedCacheContextInterface { - use DefaultCacheContextTrait; - - /** - * @todo remove this? - */ - protected $menuName; - /** * {@inheritdoc} */ @@ -35,20 +28,9 @@ * {@inheritdoc} */ public function getContext($menu_name = NULL) { - // @todo remove this? - if ($menu_name === NULL) { - $menu_name = $this->menuName; - } $active_trail = $this->container->get('menu.active_trail') ->getActiveTrailIds($menu_name); - return 'menu_trail.' . $menu_name . '|' . implode('|', $active_trail); - } - - /** - * @todo remove this? - */ - public function setParameter($parameter) { - $this->menuName = $parameter; + return new CacheContextValue('menu_trail.' . $menu_name . '|' . implode('|', $active_trail)); } } diff -u b/core/lib/Drupal/Core/Cache/Context/PagersCacheContext.php b/core/lib/Drupal/Core/Cache/Context/PagersCacheContext.php --- b/core/lib/Drupal/Core/Cache/Context/PagersCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/PagersCacheContext.php @@ -12,13 +12,6 @@ */ class PagersCacheContext extends RequestStackCacheContextBase implements CalculatedCacheContextInterface { - use DefaultCacheContextTrait; - - /** - * @todo remove this? - */ - protected $pager_id; - /** * {@inheritdoc} */ @@ -32,20 +25,13 @@ * @see pager_find_page() */ public function getContext($pager_id = NULL) { - if ($pager_id === NULL) { - $pager_id = $this->pager_id; - } // The value of the 'page' query argument contains the information that // controls *all* pagers. if ($pager_id === NULL) { - return 'pager' . $this->requestStack->getCurrentRequest()->query->get('page', ''); + return new CacheContextValue('pager' . $this->requestStack->getCurrentRequest()->query->get('page', '')); } - return 'pager.' . $pager_id . '.' . pager_find_page($pager_id); - } - - public function setParameter($parameter) { - $this->pager_id = $parameter; + return new CacheContextValue('pager.' . $pager_id . '.' . pager_find_page($pager_id)); } } diff -u b/core/lib/Drupal/Core/Cache/Context/QueryArgsCacheContext.php b/core/lib/Drupal/Core/Cache/Context/QueryArgsCacheContext.php --- b/core/lib/Drupal/Core/Cache/Context/QueryArgsCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/QueryArgsCacheContext.php @@ -16,8 +16,6 @@ */ class QueryArgsCacheContext extends RequestStackCacheContextBase implements CalculatedCacheContextInterface { - use DefaultCacheContextTrait; - /** * {@inheritdoc} */ @@ -30,10 +28,10 @@ */ public function getContext($query_arg = NULL) { if ($query_arg === NULL) { - return $this->requestStack->getCurrentRequest()->getQueryString(); + return new CacheContextValue($this->requestStack->getCurrentRequest()->getQueryString()); } else { - return $this->requestStack->getCurrentRequest()->query->get($query_arg); + return new CacheContextValue($this->requestStack->getCurrentRequest()->query->get($query_arg)); } } diff -u b/core/lib/Drupal/Core/Cache/Context/RequestFormatCacheContext.php b/core/lib/Drupal/Core/Cache/Context/RequestFormatCacheContext.php --- b/core/lib/Drupal/Core/Cache/Context/RequestFormatCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/RequestFormatCacheContext.php @@ -12,8 +12,6 @@ */ class RequestFormatCacheContext extends RequestStackCacheContextBase { - use DefaultCacheContextTrait; - /** * {@inheritdoc} */ @@ -25,7 +23,7 @@ * {@inheritdoc} */ public function getContext() { - return $this->requestStack->getCurrentRequest()->getRequestFormat(); + return new CacheContextValue($this->requestStack->getCurrentRequest()->getRequestFormat()); } } diff -u b/core/lib/Drupal/Core/Cache/Context/RouteCacheContext.php b/core/lib/Drupal/Core/Cache/Context/RouteCacheContext.php --- b/core/lib/Drupal/Core/Cache/Context/RouteCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/RouteCacheContext.php @@ -14,8 +14,6 @@ */ class RouteCacheContext implements CacheContextInterface { - use DefaultCacheContextTrait; - /** * The route match. * @@ -44,7 +42,7 @@ * {@inheritdoc} */ public function getContext() { - return $this->routeMatch->getRouteName() . hash('sha256', serialize($this->routeMatch->getRawParameters()->all())); + return new CacheContextValue($this->routeMatch->getRouteName() . hash('sha256', serialize($this->routeMatch->getRawParameters()->all()))); } } diff -u b/core/lib/Drupal/Core/Cache/Context/RouteNameCacheContext.php b/core/lib/Drupal/Core/Cache/Context/RouteNameCacheContext.php --- b/core/lib/Drupal/Core/Cache/Context/RouteNameCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/RouteNameCacheContext.php @@ -12,8 +12,6 @@ */ class RouteNameCacheContext extends RouteCacheContext { - use DefaultCacheContextTrait; - /** * {@inheritdoc} */ @@ -25,7 +23,7 @@ * {@inheritdoc} */ public function getContext() { - return $this->routeMatch->getRouteName(); + return new CacheContextValue($this->routeMatch->getRouteName()); } } diff -u b/core/lib/Drupal/Core/Cache/Context/SiteCacheContext.php b/core/lib/Drupal/Core/Cache/Context/SiteCacheContext.php --- b/core/lib/Drupal/Core/Cache/Context/SiteCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/SiteCacheContext.php @@ -20,8 +20,6 @@ */ class SiteCacheContext extends RequestStackCacheContextBase { - use DefaultCacheContextTrait; - /** * {@inheritdoc} */ @@ -34,7 +32,7 @@ */ public function getContext() { $request = $this->requestStack->getCurrentRequest(); - return $request->getSchemeAndHttpHost() . $request->getBaseUrl(); + return new CacheContextValue($request->getSchemeAndHttpHost() . $request->getBaseUrl()); } } diff -u b/core/lib/Drupal/Core/Cache/Context/ThemeCacheContext.php b/core/lib/Drupal/Core/Cache/Context/ThemeCacheContext.php --- b/core/lib/Drupal/Core/Cache/Context/ThemeCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/ThemeCacheContext.php @@ -15,8 +15,6 @@ */ class ThemeCacheContext implements CacheContextInterface { - use DefaultCacheContextTrait; - /** * The theme manager. * @@ -45,7 +43,7 @@ * {@inheritdoc} */ public function getContext() { - return $this->themeManager->getActiveTheme()->getName() ?: 'stark'; + return new CacheContextValue($this->themeManager->getActiveTheme()->getName() ?: 'stark'); } } diff -u b/core/lib/Drupal/Core/Cache/Context/UrlCacheContext.php b/core/lib/Drupal/Core/Cache/Context/UrlCacheContext.php --- b/core/lib/Drupal/Core/Cache/Context/UrlCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/UrlCacheContext.php @@ -12,8 +12,6 @@ */ class UrlCacheContext extends RequestStackCacheContextBase { - use DefaultCacheContextTrait; - /** * {@inheritdoc} */ @@ -25,7 +23,7 @@ * {@inheritdoc} */ public function getContext() { - return $this->requestStack->getCurrentRequest()->getUri(); + return new CacheContextValue($this->requestStack->getCurrentRequest()->getUri()); } } diff -u b/core/lib/Drupal/Core/Cache/Context/UserCacheContext.php b/core/lib/Drupal/Core/Cache/Context/UserCacheContext.php --- b/core/lib/Drupal/Core/Cache/Context/UserCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/UserCacheContext.php @@ -14,8 +14,6 @@ */ class UserCacheContext implements CacheContextInterface { - use DefaultCacheContextTrait; - /** * Constructs a new UserCacheContext service. * @@ -37,7 +35,7 @@ * {@inheritdoc} */ public function getContext() { - return "u." . $this->user->id(); + return new CacheContextValue("u." . $this->user->id(), $this->getCacheTags()); } /** diff -u b/core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php b/core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php --- b/core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php @@ -18,7 +18,2 @@ /** - * @todo remove this? - */ - protected $role; - - /** * {@inheritdoc} @@ -33,27 +28,17 @@ public function getContext($role = NULL) { - if ($role === NULL) { - $role = $this->role; - } // User 1 does not actually have any special behavior for roles; this is // added as additional security and backwards compatibility protection for // SA-CORE-2015-002. // @todo Remove in Drupal 9.0.0. if ($this->user->id() == 1) { - return 'is-super-user'; + return new CacheContextValue('is-super-user'); } if ($role === NULL) { - return 'r.' . implode(',', $this->user->getRoles()); + return new CacheContextValue('r.' . implode(',', $this->user->getRoles())); } else { - return 'r.' . $role . '.' . (in_array($role, $this->user->getRoles()) ? '0' : '1'); + return new CacheContextValue('r.' . $role . '.' . (in_array($role, $this->user->getRoles()) ? '0' : '1')); } } - /** - * @todo remove this? - */ - public function setParameter($parameter) { - $this->role = $parameter; - } - } diff -u b/core/lib/Drupal/Core/Render/RenderCache.php b/core/lib/Drupal/Core/Render/RenderCache.php --- b/core/lib/Drupal/Core/Render/RenderCache.php +++ b/core/lib/Drupal/Core/Render/RenderCache.php @@ -307,13 +307,13 @@ $context_objects = $this->cacheContextsManager->convertTokensToObjects($elements['#cache']['contexts']); $contexts = []; foreach ($context_objects as $context) { - $contexts[] = $context->getContext(); - } - if (isset($elements['#cache']['tags'])) { - $elements['#cache']['tags'] = Cache::mergeTags($elements['#cache']['tags'], $context->getCacheTags()); - } - else { - $elements['#cache']['tags'] = $context->getCacheTags(); + $contexts[] = $context->getValue(); + if (isset($elements['#cache']['tags'])) { + $elements['#cache']['tags'] = Cache::mergeTags($elements['#cache']['tags'], $context->getCacheTags()); + } + else { + $elements['#cache']['tags'] = $context->getCacheTags(); + } } $cid_parts = array_merge($cid_parts, $contexts); } diff -u b/core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php b/core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php --- b/core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php +++ b/core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php @@ -7,6 +7,7 @@ namespace Drupal\node\Cache; +use Drupal\Core\Cache\Context\CacheContextValue; use Drupal\Core\Cache\Context\CalculatedCacheContextInterface; use Drupal\Core\Cache\Context\UserCacheContext; @@ -36,13 +37,10 @@ * {@inheritdoc} */ public function getContext($operation = NULL) { - if ($operation === NULL) { - $operation = $this->operation; - } // If the current user either can bypass node access then we don't need to // determine the exact node grants for the current user. if ($this->user->hasPermission('bypass node access')) { - return 'all'; + return new CacheContextValue('all'); } // When no specific operation is specified, check the grants for all three @@ -52,17 +50,13 @@ foreach (['view', 'update', 'delete'] as $op) { $result[] = $this->checkNodeGrants($op); } - return implode('-', $result); + return new CacheContextValue(implode('-', $result)); } else { - return $this->checkNodeGrants($operation); + return new CacheContextValue($this->checkNodeGrants($operation)); } } - public function setParameter($parameter) { - $this->operation = $parameter; - } - /** * Checks the node grants for the given operation. * diff -u b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php --- b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php +++ b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php @@ -214,7 +214,7 @@ $cache_contexts = \Drupal::service('cache_contexts_manager')->convertTokensToObjects($this->displayHandler->getCacheMetadata()['contexts']); foreach ($cache_contexts as $cache_context) { - $key_data[] = $cache_context->getContext(); + $key_data[] = $cache_context->getValue(); } $this->resultsKey = $this->view->storage->id() . ':' . $this->displayHandler->display['id'] . ':results:' . hash('sha256', serialize($key_data)); diff -u b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php --- b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Cache\Context\CacheContextsManager; use Drupal\Core\Cache\Context\CacheContextInterface; +use Drupal\Core\Cache\Context\CacheContextValue; use Drupal\Core\Cache\Context\CalculatedCacheContextInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Tests\UnitTestCase; @@ -78,7 +79,7 @@ } /** - * @covers ::convertTokensToKeys + * @covers ::convertTokensToObjects */ public function testConvertTokensToKeys() { $container = $this->getMockContainer(); @@ -91,15 +92,15 @@ ]); $expected = [ - 'baz.cnenzrgreN', - 'baz.cnenzrgreO', - 'bar', + new CacheContextValue('baz.cnenzrgreN'), + new CacheContextValue('baz.cnenzrgreO'), + new CacheContextValue('bar'), ]; $this->assertEquals($expected, $new_keys); } /** - * @covers ::convertTokensToKeys + * @covers ::convertTokensToObjects * * @expectedException \InvalidArgumentException * @expectedExceptionMessage "non-cache-context" is not a valid cache context ID. @@ -112,7 +113,7 @@ } /** - * @covers ::convertTokensToKeys + * @covers ::convertTokensToObjects * * @expectedException \Exception * @@ -231,7 +232,7 @@ * {@inheritdoc} */ public function getContext() { - return 'bar'; + return new CacheContextValue('bar'); } } @@ -255,7 +256,7 @@ if (!is_string($parameter) || strlen($parameter) === 0) { throw new \Exception(); } - return 'baz.' . str_rot13($parameter); + return new CacheContextValue('baz.' . str_rot13($parameter)); } } only in patch2: unchanged: --- a/core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php @@ -46,7 +46,7 @@ public static function getLabel() { * {@inheritdoc} */ public function getContext() { - return 'ph.' . $this->permissionsHashGenerator->generate($this->user); + return new CacheContextValue('ph.' . $this->permissionsHashGenerator->generate($this->user)); } } only in patch2: unchanged: --- /dev/null +++ b/core/lib/Drupal/Core/Cache/Context/CacheContextValue.php @@ -0,0 +1,60 @@ +value = $value; + $this->cacheTags = $cache_tags; + } + + /** + * Gets the cache context. + * + * @return string + */ + public function getValue() { + return $this->value; + } + + /** + * Gets the cache tags associated for the cache context. + * + * @return \Drupal\Core\Cache\Context\CacheContextValue. + */ + public function getCacheTags() { + return $this->cacheTags; + } + +} only in patch2: unchanged: --- a/core/lib/Drupal/Core/Cache/Context/TimeZoneCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/TimeZoneCacheContext.php @@ -27,7 +27,7 @@ public static function getLabel() { public function getContext() { // date_default_timezone_set() is called in AccountProxy::setAccount(), so // we can safely retrieve the timezone. - return date_default_timezone_get(); + return new CacheContextValue(date_default_timezone_get()); } }