prc b6c02717e6 Upload complete no-internet building environment. | hace 1 año | |
---|---|---|
.. | ||
index.d.ts | hace 1 año | |
index.js | hace 1 año | |
license | hace 1 año | |
package.json | hace 1 año | |
readme.md | hace 1 año |
Useful when you need to cache something and limit memory usage.
Inspired by the hashlru
algorithm, but instead uses Map
to support keys of any type, not just strings, and values can be undefined
.
$ npm install quick-lru
const QuickLRU = require('quick-lru');
const lru = new QuickLRU({maxSize: 1000});
lru.set('🦄', '🌈');
lru.has('🦄');
//=> true
lru.get('🦄');
//=> '🌈'
Returns a new instance.
Type: object
Required\
Type: number
The maximum number of items before evicting the least recently used items.
Optional\
Type: (key, value) => void
Called right before an item is evicted from the cache.
Useful for side effects or for items like object URLs that need explicit cleanup (revokeObjectURL
).
The instance is iterable
so you can use it directly in a for…of
loop.
Both key
and value
can be of any type.
Set an item. Returns the instance.
Get an item.
Check if an item exists.
Get an item without marking it as recently used.
Delete an item.
Returns true
if the item is removed or false
if the item doesn't exist.
Delete all items.
Iterable for all the keys.
Iterable for all the values.
The stored item count.