stale-lru-cache is an in-memory LRU cache for Node.js that implements stale-while-revalidate strategy, allowing cached items to be served stale while being refreshed in the background. Version 5.1.1 is the latest stable release. It supports custom Cache-Control headers for HTTP caching, max age, max size, and configurable item sizing. Key differentiators: fault-tolerant background revalidation that hides refresh latency, shields from revalidation errors, and optimizes hit-ratio by discarding least recently used items first.
npm install stale-lru-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a stale-while-revalidate cache with maxSize 100, 10 min maxAge, 24h stale window, and a revalidation function. Demonstrates set/get with synchronous initial data.
Use has() to check existence before get() if needed.
Always pass callback(null, value, null) if no options.
Use callback(error, value) pattern instead of callback(value, error) from earlier versions.
Ensure values are in seconds (e.g., 600 for 10 minutes).
Run 'npm install stale-lru-cache' in your project directory.
Use 'var Cache = require('stale-lru-cache');' or default ESM import.Ensure callback is invoked: callback(null, value, options);
No dependency data recorded yet.