Breaking
- Require Node.js 22 378efc2
- Make
.keys(),.values(), and the iterator (for…of, spread) go from the oldest item to the newest, like.entries()and.forEach()378efc2- Before, they started with the most recent batch of items and then went to the older batch, so the order was neither oldest first nor newest first.
- Throw a
TypeErrorfor an invalidmaxSize, also in.resize()378efc2- It must be a whole number greater than
0, orInfinity. Before, a fraction like1.5or a string like'10'was accepted.
- It must be a whole number greater than
- Throw a
TypeErrorfor a negative orNaNmaxAge378efc2- Before, only
0threw. A negative value was accepted, andNaNsilently meant no expiration.
- Before, only
- Call
onEvictionafter the item is removed, not right before 378efc2
Improvements
- Add
.getOrInsert()and.getOrInsertComputed()methods 378efc2- They work like the
Mapmethods with the same names from the upsert proposal.
- They work like the
- Type the third argument of the
.forEach()callback as theQuickLRUinstance instead ofMap378efc2 - Make the type parameters of the
Optionstype optional 378efc2
Fixes
- Fix
onEvictionbeing called for an item that was overwritten with.set()and is still in the cache 378efc2 - Fix
.evict()letting the cache grow without limit when it is called repeatedly between writes 378efc2 - Fix infinite recursion when
onEvictionreads an expired item 378efc2 - Fix iteration skipping items, or visiting items added during the loop, when the cache changes during iteration 378efc2
- Fix the TypeScript types with TypeScript 5.6 and later 378efc2
QuickLRUwas not assignable toMap, and iterator helpers like.keys().map()were missing.