fix: skip use-stale background job when cache already refreshed (MR-7760)#33
Merged
Conversation
…ior job Queued refresh lambdas now check whether the cache was already successfully refreshed by another job before making a network request. This prevents a storm of stale-while-revalidating jobs from all hitting upstream after a backlogged queue drains. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Replaces magic strings 'refresh after' and 'Wait between refreshes' with CACHE_IS_NOT_STALE and CACHE_STALE_REFRESH_IS_QUEUED constants, eliminating the silent-mismatch risk introduced when cacheIsCurrentlyFresh() was added. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
an-adamchuk
approved these changes
Jul 7, 2026
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.
Summary
cacheIsCurrentlyFresh()toAbstractUseStaleRequest— returnstruewhen the refresh key holds the'refresh after'marker written by a successfulwriteResponseToCache()callWhy
needsRefresh()alone doesn't work hereneedsRefresh()returnsfalsefor two distinct states:needsRefresh()'Wait between refreshes'false'refresh after'falseUsing
needsRefresh()in the closure would incorrectly bail out jobs that run quickly (within the 5-minute snooze window). Checking the actual stored value correctly distinguishes the two states.Test plan
testDeferredJobSkipsWhenCacheAlreadyRefreshed— new test: two jobs queued across thewaitBetweenRefreshesboundary; J1 runs and refreshes; J2 asserts zero additional network callsCloses MR-7760
🤖 Generated with Claude Code