diff --git a/core/lib/Drupal/Core/Cache/Cache.php b/core/lib/Drupal/Core/Cache/Cache.php index b5508a1..a5e1697 100644 --- a/core/lib/Drupal/Core/Cache/Cache.php +++ b/core/lib/Drupal/Core/Cache/Cache.php @@ -22,6 +22,14 @@ class Cache { const PERMANENT = CacheBackendInterface::CACHE_PERMANENT; /** + * + * Contains the valid cache contexts, pulled from the container. + * + * @var \Drupal\Core\Cache\CacheContextInterface[] + */ + protected static $validCacheContexts; + + /** * Merges arrays of cache contexts and removes duplicates. * * @param string[] … @@ -62,9 +70,8 @@ public static function validateContexts(array $context_tokens) { // The set of existing (thus valid) cache contexts is stored on the // container; it's safe to statically cache this because it cannot change // during the request. - static $valid_contexts; - if (!isset($valid_contexts)) { - $valid_contexts = \Drupal::getContainer()->getParameter('cache_contexts'); + if (!isset(static::$validCacheContexts)) { + static::$validCacheContexts = \Drupal::getContainer()->getParameter('cache_contexts'); } foreach ($context_tokens as $value) { @@ -76,7 +83,7 @@ public static function validateContexts(array $context_tokens) { if (strpos($value, ':') !== FALSE) { $value = substr($value, 0, strpos($value, ':')); } - if (!in_array($value, $valid_contexts)) { + if (!in_array($value, static::$validCacheContexts)) { throw new \LogicException('"' . $value. '" is not a valid cache context ID.'); } }