Skip to content

Commit a436bf9

Browse files
committed
drupal-graphql#1152 - consider cache contexts for the cache prefix
1 parent 3841ce8 commit a436bf9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/GraphQL/Execution/Executor.php

+7
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,17 @@ protected function cachePrefix() {
301301
$extensions = $this->context->getOperation()->extensions ?: [];
302302
ksort($extensions);
303303

304+
// By firing the operation event before executing the operation and before
305+
// reading from the cache different contexts might be set to control the
306+
// caching and make it possible to cache e.g. by country.
307+
$contexts = $this->context->getCacheContexts();
308+
$keys = $this->contextsManager->convertTokensToKeys($contexts)->getKeys();
309+
304310
$hash = hash('sha256', serialize([
305311
'query' => DocumentSerializer::serializeDocument($this->document),
306312
'variables' => $variables,
307313
'extensions' => $extensions,
314+
'keys' => $keys,
308315
]));
309316

310317
return $hash;

0 commit comments

Comments
 (0)