btree-lru-cache
v2.1.0
Published
Simple LRU cache with ordered eviction, built on btree-core.
Maintainers
Readme
btree-lru-cache
Simple LRU cache with ordered eviction, built on btree-core.
Install
npm install btree-lru-cacheUsage
const LruCache = require('btree-lru-cache');
const cache = new LruCache(2);
cache.set('a', 1);
cache.set('b', 2);
cache.get('a'); // marks a as recently used
cache.set('c', 3); // evicts b
cache.has('b'); // false
cache.get('a'); // 1
cache.get('c'); // 3API
| Method | Description |
| --- | --- |
| set(key, value) | Insert/update; may evict LRU entry |
| get(key) | Read and mark as recently used |
| peek(key) | Read without updating recency |
| has(key) | Check presence |
| delete(key) | Remove entry |
| clear() | Remove all |
| keys() | Keys oldest → newest |
| entries() | [key, value] oldest → newest |
| size | Current entry count |
| capacity | Max entries |
License
MIT
