Repository navigation
fix(bun-cache): one invalidation, one CDN purge - #707
Merged
Merged
Conversation
cacheResponse() ran a second invalidation pass (and a second invalidate event) after every tracked write that was settling when an invalidation began, so the README's CDN-purge recipe purged twice. Each tracked write now records, through the cache's synchronous set event, whether it was stored after the invalidation began, and only then runs the second pass; a refused or already-landed write no longer does. The listener is added with the first tracked write (bun-nest's interceptor builds one against a throwing probe). Develop fails 3 of the 4 new tests. Approved by the user, 2026-11-08.
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.
fix(bun-cache): an invalidation runs twice only when a write stored after it began
Item 10 of track G: one invalidation, one CDN purge. Item 1 of this track (the surrogate test) found that
cacheResponse()sometimes invalidated a path twice, and the second time firedinvalidateagain. The README's CDN-purge recipe then purged twice.What happened
pages.invalidate()and an unsafe method's invalidation run once.invalidate.fenced,reason: "local"), nothing is stored, and the second pass still ran.Choice: the product, not the recipe
Deduping in the recipe cannot be exact.
cacheResponse()change.setevent, which is synchronous with the store.BunCacheInterceptorbuilds one against a probe that throws on any read, and its suite caught the first version of this change doing exactly that.Effects:
Decisions (approved by the user, 2026-11-08)
Fewer
invalidateevents.invalidatefires twice for onepages.invalidate()or unsafe method only when a write stored after it began.Recommendation: accept. It is what the recipe always claimed ("purges each invalidation once"), and the remaining second event is the one a CDN needs.
Tests (
__tests__/http/methods.test.ts, "one invalidation, one pass…", 4 new)setevent) makes oneinvalidateTagscall and one event. Run withcoalesceoff and on.fencedevent, then one turn.All of them wait on events (
set,fenced,invalidate) and onesetImmediateturn, never on time. The calls are counted by wrappingcache.invalidateTags, which is synchronous at the call.Negative controls:
cacheResponse.ts: tests 1 (both) and 2 fail, 2 calls instead of 1. Test 3 passes.Also:
surrogate.test.ts: item 1'ssetImmediatedrain is gone; it is no longer needed. The test waits for its third event as before. 32 copies × 5 rounds: 0 of 160 failed (1-min load 30-33).examples/bun-cache/05-http/cdn-tags.ts) is unchanged. A step asserting one purge was tried and dropped, because it passed on develop too: the redundant event arrives a turn after any point an example can check without wrapping the cache. No test parses the README's recipe or the examples README row.Gates
bun run check: clean, 275 files.bun run lint: 0 errors.bun run format:check: clean.bun run test(everyBUN_CACHE_TEST_*URL but Upstash): 2158 pass, 150 skip, 0 fail.drivers/encrypted.test.ts"a raised clear expiry gains nothing" ("the entry expired before the test could raise it");drivers/mysql.test.tshook timeout.cacheResponseinBunCacheInterceptor):bun run test1511 pass, 7 skip, 0 fail; seeds 1 and 2: 1511 pass, 0 fail each.dts/removed afterwards.run-all.ts: 44 examples: 42 passed, 2 skipped, 0 failed. The two skips (04-drivers/sql.ts,06-tiers/separate-bus.ts) readEXAMPLE_*_URL; run directly with those set to the test servers they passed (65 and 8 checks). Directly:s3.ts36 checks,cdn-tags.ts22 checks.bun scripts/typecheck.ts: 25 projects clean.bun run format:check: clean.Approved by the user, 2026-11-08.