Skip to content

feat(cache/unstable): improve LruCache ejection callbacks and add peek()#7047

Open
tomas-zijdemans wants to merge 2 commits intodenoland:mainfrom
tomas-zijdemans:lru-cache-size
Open

feat(cache/unstable): improve LruCache ejection callbacks and add peek()#7047
tomas-zijdemans wants to merge 2 commits intodenoland:mainfrom
tomas-zijdemans:lru-cache-size

Conversation

@tomas-zijdemans
Copy link
Contributor

  • onEject callback now receives a reason parameter ("evicted", "deleted", or "cleared") so callers can distinguish why an entry was removed.
  • New peek() method for reading a value without promoting it.
  • has() no longer promotes entries in the eviction order
  • Constructor validates maxSize, rejecting zero, negative, non-integer, and non-finite values.
  • maxSize is now a readonly getter backed by a private field.
  • onEject callback is now optional, and clear() calls it for every entry
  • calling set, delete, or clear inside an onEject callback throws instead of corrupting state.
  • delete() returns false immediately for non-existent keys and fires onEject only after the entry is fully removed.
  • Test coverage improved.

@tomas-zijdemans tomas-zijdemans requested a review from kt3k as a code owner March 13, 2026 12:50
@github-actions github-actions bot added the cache label Mar 13, 2026
@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.02%. Comparing base (6df7f21) to head (2eae12c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7047   +/-   ##
=======================================
  Coverage   94.01%   94.02%           
=======================================
  Files         627      627           
  Lines       50029    50087   +58     
  Branches     8807     8823   +16     
=======================================
+ Hits        47037    47094   +57     
  Misses       2413     2413           
- Partials      579      580    +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.

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.

1 participant