isaacs/node-lru-cache — explained in plain English
Analysis updated 2026-06-26
Cache expensive API or database results in memory with automatic eviction when a count or size limit is reached
Set per-item TTLs so cached entries expire automatically after a given number of milliseconds
Use the async fetch mode to return stale cached data immediately while refreshing it in the background
Register a dispose callback to clean up file handles or connections when items are evicted from the cache
| isaacs/node-lru-cache | w37fhy/quantumultx | nirmalscaria/le-git-graph | |
|---|---|---|---|
| Stars | 5,873 | 5,875 | 5,878 |
| Language | JavaScript | JavaScript | JavaScript |
| Setup difficulty | easy | moderate | easy |
| Complexity | 2/5 | 1/5 | 1/5 |
| Audience | developer | general | developer |
Figures from each repo's GitHub metadata at analysis time.
node-lru-cache is a JavaScript library that gives you a fast in-memory cache with automatic eviction. LRU stands for "least recently used," which describes the eviction rule: when the cache reaches its limit, the item that has not been accessed for the longest time is removed to make room for new entries. You use it when you want to keep frequently needed data close at hand without memory growing without bound. You create a cache by passing a configuration object with at least one size constraint. The max option limits by item count and pre-allocates storage for that many slots when the cache is created, which makes reads and writes fast. The maxSize option limits by total storage, where each item provides its own size when stored, suitable when items vary significantly in size. You can also set a TTL in milliseconds, after which items are treated as absent when requested. The library supports any type of key, not just strings. Object keys work, but lookup requires the exact same object reference, not just an object with matching properties. You can register a dispose callback that fires whenever an item leaves the cache, letting you release external resources like file handles or connections. An async fetch mode lets you supply a function the cache calls when it needs to fill a missing entry. This supports stale-while-revalidate patterns, where a stale value is returned immediately while a fresh one is fetched in the background. Tracing support is built in via Node.js diagnostics channels, allowing monitoring tools to observe cache activity. The library is available on npm and works in both Node.js and browser environments. It does not store undefined values, as that value is used internally to signal a missing key.
node-lru-cache is a fast JavaScript in-memory cache that automatically evicts the least recently used items when full, letting you keep frequently needed data close at hand without memory growing without bound.
Mainly JavaScript. The stack also includes JavaScript, Node.js.
Setup difficulty is rated easy, with roughly 5min to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Verify against the repo before relying on details.