root 3bf41bf355 update | il y a 1 an | |
---|---|---|
.. | ||
index.d.ts | il y a 1 an | |
index.js | il y a 1 an | |
license | il y a 1 an | |
package.json | il y a 1 an | |
readme.md | il y a 1 an |
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.
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.