peach a19a732be8 commit message | 2 年之前 | |
---|---|---|
.. | ||
index.d.ts | 2 年之前 | |
index.js | 2 年之前 | |
license | 2 年之前 | |
package.json | 2 年之前 | |
readme.md | 2 年之前 |
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.