Repository navigation
fix: honor per-entry ttl on compressed cache entries - #149
Merged
Merged
Conversation
memoize reads ttl and staleTtl from the stored value. Brotli stores a Buffer, so those fields were dropped and every compressed entry kept the default lifetime: a 1s ttl stayed a HIT for most of the 24h default and never entered the stale window. Store the lifetimes beside the payload and keep loading older raw buffers. Co-authored-by: kikohumanbeatbox <kikohumanbeatbox@gmail.com>
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Response headers read ttl through the envelope check, so a cached value that already had a compressed field was sent with max-age=NaN. Co-authored-by: Cursor <cursoragent@cursor.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.
Compressed responses ignored the
ttl/staleTtlreturned fromget()and stayed fresh for the default lifetime (24h, stale window of 1h).@keyvhq/memoizedecides expiry from the stored value. Withcompress: truethat value is a brotliBuffer, which has nottlorstaleTtl, so a 1s entry was still aHITafter several seconds and never becameSTALE.The compressed payload is now stored next to those two lifetimes. Older entries that are raw buffers still decompress.
Validation:
npx ava(38 tests). The new cases fail on the previous source (HITinstead ofEXPIRED/STALE) and pass with this change.Note
Medium Risk
Changes core cache expiry behavior for compressed entries; backward-compatible for existing buffer keys but alters when responses refresh or go stale.
Overview
Fixes per-entry
ttl/staleTtlwhencompress: true. Previously@keyvhq/memoizeonly saw a brotliBuffer, so entries kept the default 24h lifetime and ignored values fromget().Writes now use a
CompressedEntryenvelope (compressed+ttl+staleTtl) viastoreValue, withttlOf/staleTtlOffeeding memoize expiry. Reads go throughloadValue, which still accepts legacy raw buffers. Response headers use lifetimes from the decompressed payload, with a guard so a user-ownedcompressedfield on the cached object is not treated as the storage envelope.Types add
CompressedEntryand widenCacheProviderget/set. Tests cover HIT/EXPIRED/STALE under compression, backward-compatible raw buffer hits, function-based TTL, and domaincompressedfields.Reviewed by Cursor Bugbot for commit 450ace4. Bugbot is set up for automated code reviews on this repo. Configure here.