fix: make cache bypass actually refresh and stay uncached - #142
Open
cursor[bot] wants to merge 3 commits into
Open
fix: make cache bypass actually refresh and stay uncached#142cursor[bot] wants to merge 3 commits into
cursor[bot] wants to merge 3 commits into
Conversation
Two bypass paths advertised the wrong HTTP caching behavior: 1. Custom keys that pass query-string force values (e.g. req.query.force === 'true') never refreshed because @keyvhq/memoize only treats forceExpiration === true as expired. Headers said BYPASS while the stale body was still served. Coerce the flag to boolean before memoize. 2. Returning null/undefined from .get() is documented as preventing caching, but responses still sent public max-age Cache-Control, so CDNs could store fallback/error bodies. Send no-store when memoize produced no payload. Co-authored-by: kikohumanbeatbox <kikohumanbeatbox@gmail.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MTbj6CYXGsk6rhXx7J8SUP
Kikobeats
marked this pull request as ready for review
August 5, 2026 09:16
Contributor
Author
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c427c12. Configure here.
Boolean() coercion keeps custom keys aligned with the default presence-based bypassQueryParameter semantics. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QpdsjFkcyG4NHixpoVwWKq
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.

Bug and impact
Two cache-bypass paths could serve or advertise the wrong content:
[cacheKey, req.query.force], a request with?force=truereportedX-Cache-Status: BYPASSandCache-Control: no-storebut still returned the stale cached body without calling.get()again..get()bypass — Documented as preventing caching (e.g. error/fallback responses), but responses still sentCache-Control: public, max-age=…, so shared caches/CDNs could store that body for the default TTL.Root cause
@keyvhq/memoizeonly treatsforceExpiration === trueas a forced refresh. Query-string values are strings ('true'), so memoize kept the hit while this package's header logic treated any truthy value as BYPASS.setHeadersalways built public cacheable headers unlessforceExpirationwas set; a storage bypass (raw == null) did not opt out of shared HTTP caching.Fix
Boolean(forceExpiration)before passing it to memoize.raw == null), sendprivate, no-cache, no-store, max-age=0(status remainsMISS).Validation
?force=truerefresh and null-bypassCache-Control.npm test: 29/29 passed.Note
Medium Risk
Changes HTTP
Cache-Controland memoize key semantics for bypass paths; behavior shifts for custom keys and null.get()responses but is covered by new tests.Overview
Fixes two mismatches between HTTP cache headers/status and what
@keyvhq/memoizeactually does.Custom key bypass: Array keys
[cacheKey, forceFlag]now go throughmemoKey, which passesBoolean(forceFlag)into memoize so a truthy query value (e.g.?force=true) triggers a real refresh instead of BYPASS headers with a stale body. README notes that any present force query value is truthy (including?force=false); use an explicit boolean inkeyfor value-based semantics.Null/undefined
.get(): When memoize returns no payload (raw == null), responses getprivate, no-cache, no-store, max-age=0via a newpreventCachingflag insetHeaders, so bypass/error paths are not advertised as publicly cacheable.Regression tests cover null-bypass
Cache-Controland custom-key force refresh behavior.Reviewed by Cursor Bugbot for commit 1cc85ce. Bugbot is set up for automated code reviews on this repo. Configure here.