feat(cache): add cleanup callback to LruCache and TtlCache#6857
feat(cache): add cleanup callback to LruCache and TtlCache#6857kt3k merged 3 commits intodenoland:mainfrom
LruCache and TtlCache#6857Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6857 +/- ##
=======================================
Coverage 94.09% 94.10%
=======================================
Files 578 578
Lines 42654 42676 +22
Branches 6781 6784 +3
=======================================
+ Hits 40136 40159 +23
+ Misses 2467 2466 -1
Partials 51 51 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hmm, could work, I think it depends less on cleanness of the interface, and more on whether setting/changing/adding (/removing?) eject handlers after creation is a useful feature and/or a footgun. Also what should this do? const cache = new LruCache(n)
.onEject(() => console.log(1))
.onEject(() => console.log(2)) |
As for now, this would just print 2
I can't think in a scenario where this would be bad |
|
The main idea looks good to me.
I'd prefer this to be an option instead of a method. Making it an option would make it clearer that it only handles a single callback, not multiple ones. |
🫡 |
LruCache and TtlCache
Closes #6851
This PR adds a
option: { onEject: (ejectedKey: K, ejectedValue: V) => void) }param toLruCacheandTtlCacheconstructor.