core/lib/Drupal/Core/Cache/Cache.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/lib/Drupal/Core/Cache/Cache.php b/core/lib/Drupal/Core/Cache/Cache.php index e73aee6..587c95d 100644 --- a/core/lib/Drupal/Core/Cache/Cache.php +++ b/core/lib/Drupal/Core/Cache/Cache.php @@ -70,16 +70,15 @@ public static function validateContexts(array $context_tokens) { // container; it's safe to statically cache this because it cannot change // during the request. Initialize the set of valid context tokens with this. if (!isset(static::$validContextTokens)) { - static::$validContextTokens = \Drupal::getContainer()->getParameter('cache_contexts'); + static::$validContextTokens = array_flip(\Drupal::getContainer()->getParameter('cache_contexts')); } - $valid = array_flip(static::$validContextTokens); foreach ($context_tokens as $context_token) { if (!is_string($context_token)) { throw new \LogicException('Cache contexts must be strings, ' . gettype($context_token) . ' given.'); } - if (isset($valid[$context_token])) { + if (isset(static::$validContextTokens[$context_token])) { continue; } @@ -92,8 +91,8 @@ public static function validateContexts(array $context_tokens) { if (strpos($context_id, ':') !== FALSE) { $context_id = substr($context_id, 0, strpos($context_id, ':')); } - if (isset($valid[$context_id])) { - static::$validContextTokens[] = $context_token; + if (isset(static::$validContextTokens[$context_id])) { + static::$validContextTokens[$context_token] = TRUE; } else { throw new \LogicException('"' . $context_id . '" is not a valid cache context ID.');