Simple LRU (Least Recently Used) cache implementation on top of LevelUP. Version 1.0.0 is the current stable release with no active development. It uses timestamps for eviction ordering, trading off worst-case consistency for simplicity. Unlike other caches, it avoids race conditions by performing all operations atomically within LevelUP batches, making it suitable for single-machine concurrent usage but not recommended for distributed systems. The cache stores multiple records per key with timestamps, cleaning up old records on each put and get. It requires a LevelUP instance with any LevelDOWN backend and sets a loose limit for key count.
npm install level-lru-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Create a LevelUP instance with memdown, initialize a level-lru-cache with limit 100, then put and get a value asynchronously.
Consider using monotonic clock sources or add microsecond precision to avoid ties.
Implement your own expiration layer on top, or use a different caching library like lru-cache with TTL support.
If write-heavy, consider tuning the limit or using a different cache.
Set a slightly smaller limit than desired if exactness is needed.
const db = levelup(memdown()); const cache = new Cache(db, 100);
const cache = new Cache(db, 100);
Pass a valid LevelUP instance. Example: const db = levelup(memdown()); const cache = new Cache(db, 100);