Skip to content

feat(caching): retain validator entries past expiry for conditional revalidation (v2.1.0) - #1

Merged
FranRuiz98 merged 1 commit into
masterfrom
claude/beautiful-shamir-443a5f
Jul 21, 2026
Merged

feat(caching): retain validator entries past expiry for conditional revalidation (v2.1.0)#1
FranRuiz98 merged 1 commit into
masterfrom
claude/beautiful-shamir-443a5f

Conversation

@FranRuiz98

Copy link
Copy Markdown
Owner

Entries with an ETag or Last-Modified validator were physically evicted from the store exactly when their freshness lifetime (plus stale windows) elapsed, so CachingMiddleware could never send If-None-Match / If-Modified-Since for them — every expiry degraded to a full refetch. This is the root cause behind the Demo 2 workaround in 4c599ee.

  • Add CacheOptions.RevalidationGraceSeconds (default 300, 0 = previous behavior): extra store retention applied only to entries carrying a validator, in both MemoryCacheStore and DistributedCacheStore.
  • New CacheOptions-taking constructors on both stores; the existing single-argument constructors remain and use defaults.
  • Wire the option through DI as a structural option (read at registration time, like MaxCacheSize).
  • Add real-clock regression tests: existing revalidation tests advance FakeTimeProvider while IMemoryCache evicts on the system clock, so physical eviction never fired in tests and the bug went unnoticed. RealClockRevalidationTests would have caught it.

…evalidation (v2.1.0)

Entries with an ETag or Last-Modified validator were physically evicted
from the store exactly when their freshness lifetime (plus stale windows)
elapsed, so CachingMiddleware could never send If-None-Match /
If-Modified-Since for them — every expiry degraded to a full refetch.
This is the root cause behind the Demo 2 workaround in 4c599ee.

- Add CacheOptions.RevalidationGraceSeconds (default 300, 0 = previous
  behavior): extra store retention applied only to entries carrying a
  validator, in both MemoryCacheStore and DistributedCacheStore.
- New CacheOptions-taking constructors on both stores; the existing
  single-argument constructors remain and use defaults.
- Wire the option through DI as a structural option (read at
  registration time, like MaxCacheSize).
- Add real-clock regression tests: existing revalidation tests advance
  FakeTimeProvider while IMemoryCache evicts on the system clock, so
  physical eviction never fired in tests and the bug went unnoticed.
  RealClockRevalidationTests would have caught it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@FranRuiz98
FranRuiz98 merged commit 0c65884 into master Jul 21, 2026
2 checks passed
@FranRuiz98
FranRuiz98 deleted the claude/beautiful-shamir-443a5f branch July 21, 2026 14:19
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.

1 participant