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.
npm install weak-lru-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Imports WeakLRUCache, creates a cache instance, sets and gets a value; demonstrates basic usage with an object.
Always use object values if you want weak reference behavior.
Use getValue() and setValue() instead of Map's get/set to get LRFU expiration and weak behavior.
Use Node.js v14.10 or later, or enable the harmony flag in v13.
Adjust expirationPriority to match your memory budget; for a 100 MB limit, set priority = sizeOfObject >> 10.
Periodically call .expire() or .delete() to clean up finalized entries if memory usage is a concern.
Use 'const { WeakLRUCache } = require('weak-lru-cache');' or 'import WeakLRUCache from 'weak-lru-cache';'Upgrade Node.js to v14.10+ or run with '--harmony-weak-ref' flag.
Use 'cache.setValue(key, value)' or ensure you imported WeakLRUCache correctly.
No dependency data recorded yet.