kv-lru-cache
v1.0.3
Published
Key-value least-recently-used (LRU) cache module written in Typescript with zero dependencies.
Downloads
5
Maintainers
Readme
KV LRU Cache
Key-value least-recently-used (LRU) cache module written in Typescript with zero dependencies.
See how it's implemented at my blog post.
Installation
npm i kv-lru-cache
Usage
import Cache from 'kv-lru-cache';
const cache = new Cache<string, number>(2, 3);
cache.set('a', 1);
cache.set('b', 2);
cache.set('c', 3);
cache.set('d', 4);
console.log(cache.get('a'));
// undefined
cache.clear();
cache.set('a', 1);
cache.set('b', 2);
cache.set('c', 3);
cache.get('a');
cache.set('d', 4);
console.log(cache.get('a'));
// 1