Skip to content

BREAKING(cache/unstable): refactor TtlCache#7065

Merged
bartlomieju merged 1 commit intodenoland:mainfrom
tomas-zijdemans:ttl-cache-cleanup
Mar 26, 2026
Merged

BREAKING(cache/unstable): refactor TtlCache#7065
bartlomieju merged 1 commit intodenoland:mainfrom
tomas-zijdemans:ttl-cache-cleanup

Conversation

@tomas-zijdemans
Copy link
Copy Markdown
Contributor

@tomas-zijdemans tomas-zijdemans commented Mar 26, 2026

Summary

Preparatory cleanup for the sliding expiration feature (#7046). Split out per reviewer feedback.

  • set() signature: replace positional ttl parameter with an options object ({ ttl?: number })
  • Validation: constructor and set() now throw RangeError on negative, NaN, or Infinity TTL values
  • onEject optional: no longer requires a callback; defaults to undefined instead of a no-op
  • delete() ordering: onEject fires after the entry is removed from the map, so callbacks see a consistent cache state
  • clear() calls onEject: invokes the callback for every entry (swallows intermediate errors, re-throws the first)
  • Minor guards: delete() short-circuits for non-existent keys; clearTimeout guarded against redundant calls

- 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
@github-actions github-actions Bot added the cache label Mar 26, 2026
@tomas-zijdemans tomas-zijdemans changed the title BREAKING(cache/unstable): refactor TtlCache API BREAKING(cache/unstable): refactor TtlCache Mar 26, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.38%. Comparing base (d2fb2d6) to head (9d8e309).
⚠️ Report is 11 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bartlomieju bartlomieju merged commit 21ba810 into denoland:main Mar 26, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants