caching-map v1.0.2 is an in-memory LRU cache with an ES6 Map-like API. It supports configurable cache limits, per-key cost for memory-aware eviction, per-key TTL expiration, and a materialize callback to avoid thundering herds for async resources. Unlike lru-cache, it offers easy enable/disable via zero/infinite limits and integrates with promises for async loading. Release cadence is low; no recent updates. Key differentiators include cost-based eviction, expired-key-first eviction, and full iteration order from most to least recently used.
npm install caching-mapNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic usage: create cache, set materialize callback, get with async resolution, set with TTL and cost, iteration, and expiration.
Ensure materialize returns the desired value, or if it returns a Promise, cache.get will wait for it. For synchronous caches, do not return a Promise.
To clear the cache when changing limit, call cache.clear() explicitly.
Understand that 'limit' is a budget of total cost, not key count. Set appropriate costs consistent with your limit.
If you need automatic cleanup, use lru-cache with 'ttlAutopurge' or implement periodic pruning.
If copying, costs are copied from the source only if the source is a Cache; Map entries get default cost (1). TTL is not copied from Map entries; they will have no TTL.
Assign cache.materialize = async (key) => { ... } before calling cache.get(key).Use new Cache(limit) and then assign properties like cache.materialize = fn.
Ensure materialize does not call cache.get(key) for the same key it's being called for.
const cache = new Cache(10); then cache.get(key);
No dependency data recorded yet.