weak-lru-cache

JSON →
library 1.2.2 ·javascript
verified Jun 7, 2026

A cache that combines LRU/LFU (LRFU) expiration with weak references, allowing garbage collection to reclaim unused cache entries. The cache retains strongly referenced data until it falls out of the LRU/LFU order, then uses weak references so the GC can free memory if needed. This package provides the WeakLRUCache class, which extends Map, and is suitable for Node.js (v14.10+) and Deno. Current version 1.2.2 is stable with a moderate release cadence. Compared to other LRU caches, weak-lru-cache's key differentiator is its use of weak references to avoid holding memory unnecessarily, making it ideal for large object caches where memory pressure is a concern.