LRU
LRU is using Map as underlying cache.
Table of contents
Usage
Import LRU and create new LRU object
import { LRU } from "https://deno.land/x/lru/mod.ts";
import LRU from "https://deno.land/x/lru/mod.ts";
const lru = new LRU(500); // define your max amount of entries, in this example is 500
Set, get and remove
Methods to get,set and remove key:value pair.
lru.set("key", "value");
lru.get("key");
lru.remove("key");
Has
Returns true if an element with the specified key exists in the cache otherwise false
lru.has("key");
Size
Returns amount of entries in the cache
lru.size;
Object
Returns entries as object
lru.object;
Keys
Returns array of all keys
lru.keys;
Values
Returns array of all values
lru.values;
ForEach
Executes a provided function once for each array element
lru.forEach((value, key) => {
// code
});
Map
Method creates a new array populated with the results of calling a provided function on every element in the calling array
lru.map(([key, value]) => {
// code
});
Filter
Creates a new array with all elements that pass the test implemented by the provided function
lru.filter(([key, value]) => {
// code
});
Reduce
Executes a reducer function (that you provide) on each element of the array, resulting in single output value
lru.reduce((previousValue, currentValue, currentIndex) => {
// code
}, initialValue);
Clear
Removes all entries in the cache
lru.clear();