Skip to content

fix: skip use-stale background job when cache already refreshed (MR-7760)#33

Merged
jwadhams merged 3 commits into
developmentfrom
worktree-mr-7760
Jul 7, 2026
Merged

fix: skip use-stale background job when cache already refreshed (MR-7760)#33
jwadhams merged 3 commits into
developmentfrom
worktree-mr-7760

Conversation

@jwadhams

@jwadhams jwadhams commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds cacheIsCurrentlyFresh() to AbstractUseStaleRequest — returns true when the refresh key holds the 'refresh after' marker written by a successful writeResponseToCache() call
  • The dispatched background closure checks this before making a network request; if another job has already refreshed the cache, it returns immediately
  • Covers the storm scenario: a backlogged queue drains and many duplicate refresh jobs hit upstream simultaneously — now only the first one through actually makes the network call

Why needsRefresh() alone doesn't work here

needsRefresh() returns false for two distinct states:

State refreshCacheKey value needsRefresh()
Job queued, hasn't run yet 'Wait between refreshes' false
Prior job succeeded 'refresh after' false

Using 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 the waitBetweenRefreshes boundary; J1 runs and refreshes; J2 asserts zero additional network calls
  • All 74 existing tests pass unchanged
  • CI green

Closes MR-7760

🤖 Generated with Claude Code

jwadhams and others added 3 commits July 7, 2026 11:21
…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>
@jwadhams jwadhams marked this pull request as ready for review July 7, 2026 16:48
@jwadhams jwadhams merged commit 8e2f728 into development Jul 7, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants