diff --git a/core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php b/core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php index 7dd55bf..71db8e6 100644 --- a/core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/HeadersCacheContext.php @@ -33,6 +33,8 @@ public function getContext($header = NULL) { if ($result) { $result .= '&'; } + // Sort values to minimize cache variations. + sort($value); $result .= $name . '=' . implode(',', $value); } return $result; diff --git a/core/tests/Drupal/Tests/Core/Cache/Context/HeadersCacheContextTest.php b/core/tests/Drupal/Tests/Core/Cache/Context/HeadersCacheContextTest.php index b70f187..c1f4290 100644 --- a/core/tests/Drupal/Tests/Core/Cache/Context/HeadersCacheContextTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/Context/HeadersCacheContextTest.php @@ -45,7 +45,8 @@ public function providerTestGetContext() { [['llama' => 'rocks', 'alpaca' => '', 'panda' => 'drools', 'z' => '0'], 'chicken', ''], // Header value could be an array. [['z' => ['0', '1']], NULL, 'z=0,1'], - [['z' => ['0', '1'], 'a' => []], NULL, 'a=&z=0,1'], + // Values are sorted to minimize cache variations. + [['z' => ['1', '0'], 'a' => []], NULL, 'a=&z=0,1'], ]; }