A lightweight, high-performance LRU cache for Node.js using a doubly-linked list and hash map for O(1) get/set operations. Version 1.1.0 supports optional per-key expiry (TTL), returning stale values before eviction, and methods like peek, delete, has, forEach, and toArray. Compared to alternatives like lru-cache, lru-cache-node has a simpler API, lower overhead for small caches, and no external dependencies. It is suitable for minimal caching needs in Node.js applications.
npm install lru-cache-nodeNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage: creating a cache, setting/getting values with optional TTL, peeking, deleting, checking existence, iterating, and converting to array.
Always specify maxSize to avoid unbounded growth: new Cache(maxSize).
Use set() to overwrite or reset()/delete() to clear manually. Consider a proactive cleanup mechanism for long-running apps.
If using stale: true, ensure cache is initialized with maxAge (even if large).
Replace calls to cache.contains(key) with cache.has(key).
Iterate using toArray().forEach(({key, value}) => ...) or use the built-in forEach method.Use const Cache = require('lru-cache-node'); then new Cache(maxSize, maxAge, stale);Ensure you instantiate with new: const cache = new Cache(100);
Import correctly: const Cache = require('lru-cache-node'); const cache = new Cache();No dependency data recorded yet.