Repository navigation
[6.x] Fix GraphQL and REST API response caches missing keys on invalidation under concurrent requests - #15747
Merged
Merged
Conversation
…can't escape invalidation
… can't escape invalidation The generation is memoized per request rather than per instance, since the REST cacher is resolved once per app by ApiCacheManager and would otherwise hold a stale generation in long-lived processes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… with the rest api cacher This is purely for consistency, not necessity. The GraphQL cache is bound with bind() so each resolution is already a fresh instance, but the REST cacher is held for the app's lifetime by ApiCacheManager and has to memoize per request. Using the same approach in both avoids confusion about why they differ. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request fixes an issue where cached GraphQL and REST API responses could survive a content event (like
EntrySaved) and keep being served until they expired, when they were cached by concurrent requests.This was happening because GraphQL's
DefaultCacheand the REST API'sDefaultCacherinvalidate by forgetting the keys they've recorded undergql-cache:tracked-responsesandapi-cache:tracked-responses. Those lists are updated with a non-atomic read-modify-write, so concurrent requests overwrite each other's copy of the list and some keys are never recorded.This PR fixes it by keying responses under a "generation" (a random string stored at
gql-cache:generation/api-cache:generation). Invalidating now forgets the generation key, which is a single atomic operation, so every existing response becomes unreachable whether it was tracked or not.The generation is read once per request, so
get()andput()use the same one. This means a response computed before a content event lands in the old generation, rather than being served as stale in the new one. It's memoized per request rather than per instance because the REST cacher is held for the app's lifetime byApiCacheManager, so a per-instance generation would go stale in long-lived processes. GraphQL uses the same approach for consistency.The tracked lists are still kept, so old responses are cleaned up eagerly and anyone extending either class isn't broken. They're no longer responsible for correctness though.
Fixes #15523