Skip to content

feat(cache): remember which keys a cache holds, so its hit rate comes from the traffic - #140

Merged
xevrion merged 2 commits into
mainfrom
feat/cache-keys
Dec 2, 2026
Merged

xevrion merged 2 commits into
mainfrom
feat/cache-keys

Conversation

@xevrion

@xevrion xevrion commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

What this changes

A cache or CDN can now remember which keys it holds. Turn on "Remember which keys it holds" and it keeps N of the 64 keys, fills a key when the store behind it answers a read, evicts the least recently used one when full, can expire keys after a TTL, and comes back empty after a crash or restart. Its hit rate is then measured from the traffic instead of set.

Closes #31.

Why

Every cache rolled hitRate on its own, so two caches in a row multiplied their misses and stacking caches looked free. With real keys the second cache only sees what the first one could not keep.

Off by default, so every saved design and replay link runs exactly as before.

Verification

Measured at seed 42, 30s, client at 200/s:

c1 hit c2 hit db load
two caches rolling 80% 77% 84% 7.8/s
two caches holding 16 keys, skew 1.0 63% 7% 59/s

One cache holding 16 of 64 keys: 28% with even keys, 62% at skew 1.0. Checked in the browser on Cache-aside too: 23% with the example's even keys, 56% once the client's key spread is 1.0.

  • bun run test passes (3426)
  • bun run typecheck and bun run lint pass
  • bun run build passes
  • New settings survive a share link, and an unset cacheKeys hashes byte for byte as before

@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
breakscale Ready Ready Preview Dec 2, 2026 12:46pm UTC

Request Review

@xevrion
xevrion merged commit 71748f0 into main Dec 2, 2026
10 checks passed
@xevrion
xevrion deleted the feat/cache-keys branch December 2, 2026 12:59

This branch was successfully deployed

1 active deployment
Preview – breakscale — 2965c8b6 Deployed Dec 2, 2026 by vercel[bot]
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.

Chained caches compound independent hit-rate rolls without key or tier semantics

1 participant