fix: honor a Miss returned from the go() callback instead of wrapping it in a Hit#3
Merged
Merged
Conversation
… it in a Hit go() honored a returned Hit but wrapped every other return value, including a Miss, in a new Hit. A callback returning new Cacheism.Miss(...) to signal failure on an empty cache therefore produced a Hit whose data was a Miss-shaped object (isHit true, data.isMiss true). Add a `result instanceof Miss` branch so a returned Miss is used as-is, symmetric with the existing returned-Hit handling. The Miss is persisted as a real Miss, preserving consecutiveErrors across the store round-trip. A returned Miss is authoritative and is not routed through the cacheOnFail/preferCache fallback (that remains exclusive to thrown errors). Co-Authored-By: Claude Opus 4.8 (1M context) <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.
Summary
go()honored a returnedHitbut wrapped every other return value — including aMiss— in a newHit. A callback returningnew Cacheism.Miss(...)to signal failure on an empty cache therefore produced aHitwhose.datawas a Miss-shaped object (isHit === truewhiledata.isMiss === true).This adds a
result instanceof Missbranch so a returnedMissis used as-is, symmetric with the existing returned-Hithandling:The
Missis now persisted as a realMiss(preservingconsecutiveErrorsacross the store round-trip) instead of a junkHit.Design note
A returned
Missis authoritative — it is not routed through thecacheOnFail/preferCachefallback to a stale cachedHit. That fallback stays exclusive to thrown errors. In short: a returned value is authoritative, while a throw delegates to the status policy.Tests
Three new cases in
test/memory.test.cjs(mirroring the existing "returns a Hit instance" block):Missused directly on an empty cacheMisspersisted,consecutiveErrorspreserved through the store round-tripcacheOnFail, a returnedMissoverwrites a cachedHit(pins the authoritative-vs-fallback decision)Full suite: 82 pass, 0 fail; typecheck clean.
Docs
README gains a "Callback return value" subsection documenting return-vs-throw semantics and the
new Cacheism.Miss(existing.cacheName, …)guidance, plus a clarifying note on the "Cache on Fail" status.🤖 Generated with Claude Code