lru-collection
v0.1.3
Published
In memory LRU cache with more utility methods.
Downloads
1
Maintainers
Readme
LRU Collection
A tiny and simple LRU (least recently used) implementation with more utility methods! It extends a Collection, the data structure that is used throughout Discord.js
Documentation
Some generated documentation can be found here (tick the external checkbox in the settings on the right for all the methods), most of which is the same as the documentation for the Collection class from discord.js documentation for the Collection class from discord.js.
Installation
npm install lru-collection
or
yarn add lru-collection
or
pnpm add lru-collection
Usage
import { LRUCollection } from 'lru-collection';
const lru = new LRUCollection<string, string>();
// set the maximum amount of entries we want
lru.max = 2;
lru.set('foo', 'bar');
lru.set('bar', 'baz');
lru.set('baz', 'qux');
console.log(lru.size):
// => 2
lru.has('foo');
// => false
The library also re-exports the Collection class from discord.js, so you can use it without installing it, if you want to.
import { DCollection as Collection } from 'lru-collection';