Skip to content

Commit

Permalink
drupal-graphql#1152 - consider cache contexts for the cache prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
hchonov committed Feb 6, 2021
1 parent 3841ce8 commit a436bf9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/GraphQL/Execution/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,17 @@ protected function cachePrefix() {
$extensions = $this->context->getOperation()->extensions ?: [];
ksort($extensions);

// By firing the operation event before executing the operation and before
// reading from the cache different contexts might be set to control the
// caching and make it possible to cache e.g. by country.
$contexts = $this->context->getCacheContexts();
$keys = $this->contextsManager->convertTokensToKeys($contexts)->getKeys();

$hash = hash('sha256', serialize([
'query' => DocumentSerializer::serializeDocument($this->document),
'variables' => $variables,
'extensions' => $extensions,
'keys' => $keys,
]));

return $hash;
Expand Down

0 comments on commit a436bf9

Please sign in to comment.