node-lru-cache is a cache data structure that automatically deletes the least recently used items when capacity is reached.
The tool solves the problem of managing bounded memory in applications that need fast caching. It maintains a fixed number of the most recently accessed items, evicting older entries when the limit is exceeded. The implementation offers multiple bounding strategies: you can limit by item count using the max parameter, by total storage size using maxSize with per-item size calculation, or by time-to-live with optional automatic purging. The cache treats expired items as missing and deletes them on access rather than through preemptive pruning by default.
Developers should choose this tool when they need predictable memory consumption and fast access patterns based on recency. It suits applications requiring bounded caches without the complexity of TTL-focused solutions. The README explicitly distinguishes this from TTL caching, noting that if time-based expiration is the primary concern rather than LRU eviction, the separate ttlcache package is a better fit. The tool does not store undefined values, using undefined internally to indicate missing keys; the README suggests wrapping undefined values in a sigil object if tracking them is necessary. The implementation prioritizes performance and supports diverse use cases, though enabling certain features necessarily impacts speed by requiring additional work from the cache.
Maintainers typically respond to new issues and pull requests within a day.