Skip to content

fix: honor per-entry ttl on compressed cache entries - #149

Merged
Kikobeats merged 2 commits into
masterfrom
cursor/critical-bug-management-d14b
Oct 19, 2026
Merged

Kikobeats merged 2 commits into
masterfrom
cursor/critical-bug-management-d14b

Conversation

@cursor

@cursor cursor Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Compressed responses ignored the ttl / staleTtl returned from get() and stayed fresh for the default lifetime (24h, stale window of 1h).

@keyvhq/memoize decides expiry from the stored value. With compress: true that value is a brotli Buffer, which has no ttl or staleTtl, so a 1s entry was still a HIT after several seconds and never became STALE.

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 (HIT instead of EXPIRED / STALE) and pass with this change.

Open in Web View Automation 

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 / staleTtl when compress: true. Previously @keyvhq/memoize only saw a brotli Buffer, so entries kept the default 24h lifetime and ignored values from get().

Writes now use a CompressedEntry envelope (compressed + ttl + staleTtl) via storeValue, with ttlOf / staleTtlOf feeding memoize expiry. Reads go through loadValue, which still accepts legacy raw buffers. Response headers use lifetimes from the decompressed payload, with a guard so a user-owned compressed field on the cached object is not treated as the storage envelope.

Types add CompressedEntry and widen CacheProvider get/set. Tests cover HIT/EXPIRED/STALE under compression, backward-compatible raw buffer hits, function-based TTL, and domain compressed fields.

Reviewed by Cursor Bugbot for commit 450ace4. Bugbot is set up for automated code reviews on this repo. Configure here.

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>
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0237c2ce-ae99-4418-9e8b-a6a236ef661a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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>
@Kikobeats
Kikobeats marked this pull request as ready for review October 19, 2026 14:05
@Kikobeats
Kikobeats merged commit df54794 into master Oct 19, 2026
4 checks passed
@Kikobeats
Kikobeats deleted the cursor/critical-bug-management-d14b branch October 19, 2026 14:14
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.

2 participants