Repository navigation
feat(cache): remember which keys a cache holds, so its hit rate comes from the traffic - #140
Merged
Merged
Conversation
… from the traffic (#31)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…lls cannot fill it
This branch was successfully deployed
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.
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
hitRateon 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:
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 testpasses (3426)bun run typecheckandbun run lintpassbun run buildpassescacheKeyshashes byte for byte as before