BREAKING(cache/unstable): refactor TtlCache#7065
Merged
bartlomieju merged 1 commit intodenoland:mainfrom Mar 26, 2026
Merged
Conversation
- Replace positional `ttl` parameter in `set()` with options object - Add constructor and `set()` validation (RangeError on bad values) - Make `onEject` callback optional - Fire `onEject` after entry removal in `delete()` - Call `onEject` for every entry in `clear()` (swallow intermediate errors, re-throw the first) - Skip unnecessary work in `delete()` for non-existent keys - Guard `clearTimeout` against redundant calls Made-with: Cursor
TtlCache APITtlCache
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7065 +/- ##
=======================================
Coverage 94.38% 94.38%
=======================================
Files 628 628
Lines 50178 50200 +22
Branches 8840 8851 +11
=======================================
+ Hits 47360 47383 +23
Misses 2251 2251
+ Partials 567 566 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
bartlomieju
approved these changes
Mar 26, 2026
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.
Summary
Preparatory cleanup for the sliding expiration feature (#7046). Split out per reviewer feedback.
set()signature: replace positionalttlparameter with an options object ({ ttl?: number })set()now throwRangeErroron negative,NaN, orInfinityTTL valuesonEjectoptional: no longer requires a callback; defaults toundefinedinstead of a no-opdelete()ordering:onEjectfires after the entry is removed from the map, so callbacks see a consistent cache stateclear()callsonEject: invokes the callback for every entry (swallows intermediate errors, re-throws the first)delete()short-circuits for non-existent keys;clearTimeoutguarded against redundant calls