1.0.3 • Published 2 years ago

kv-lru-cache v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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