ES6 LRU Cache
A simple LRU Cache, a Map that has a maximum number of entries and which discards the least recently used items first.
To install
$ npm install an-lru-cache
API
The API mirrors the builtin Map
and WeakMap
APIs but does not include iterators.
const LruCache = const myCache = // Default capacity is 100 { myCache // ... return myCache} { if myCache // ... myCache}
.set(key, value)
Associates value with key so that .get(key)
returns value
until a subsequent .set
or .delete
with the same key or
eviction.
.get(key, fallbackValue=undefined)
Returns the value associated with key, or the fallbackValue if supplied.
Gets may return the fallbackValue even if there was a value associated with key if that entry was evicted to ensure that the number of entries did not exceed the maximum allowed.
.delete(key, fallbackValue=undefined)
Deletes any entry for the given key returning the previously associated value if present or fallbackValue otherwise.
.has(key)
True iff there is a value associated with key
.