1. License
“Each contributor licenses you to do everything with this software that would otherwise infringe that contributor's copyright in it.”
The Blue Oak license lets you do everything with the code, also in paid products.
github.com/isaacs/node-lru-cache/blob/main/LICENSE.md2. Maintained
github.com/isaacs/node-lru-cache3. Used by agents' projects
Dependency in 47 public GitHub projects set up for AI coding agents that we scanned (0.8%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily; card checked Nov 10, 2026. Tap a verdict to see its source.How we checkedReport an error
What lru-cache does
lru-cache is a free JavaScript package that keeps recent results in your app's memory, so a slow lookup does not run again for every visitor. You set how many items it may hold; when it is full, it drops the ones nobody used for the longest time. Items can also expire after a set time.
What people build with it
Stop repeating slow lookups
Many visitors ask for the same product price or weather; the first request asks the slow source and the next ones get the saved answer.
Keep memory use bounded
Your server caches per-user data; with a limit of 500 items it never grows past that, and the least recently used ones go first.
Answers that expire
Exchange rates or a list of open slots may be reused for a few minutes, then must be looked up fresh.
Cap the cache by size
Cached pages or images differ a lot in size; give each item a size and a total limit, so a few big items cannot fill memory.
Clean up what falls out
When an item leaves the cache, a function you give it runs, for example to close a file or a connection held by that item.
Test expiry with a fake clock
Your tests move a fake clock forward instead of waiting, to check that old answers really expire.
lru-cache popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How lru-cache is used
- lru-cache is a dependency in 47 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (1.0% of the 4,867 JavaScript/TypeScript ones), #27 of 408 in utilities.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 152; those are left out of every share on this page.
- Projects that use it most often also use chalk (72.3%), Anthropic SDK (66.0%), Fuse.js (66.0%).
- It is more common in projects set up for Kiro (5.0%) than for GitHub Copilot (0.5%).
By coding agent
Often used with
More about lru-cache
Funding
- GitHub Sponsors: https://github.com/isaacs
- 23 GitHub sponsors
Alternatives
lru-cache This page
Pick node-cache for a simple in-memory key-value store with expiry, similar to memcached, when you do not need least-recently-used dropping.
Pick Keyv when the cache must live in Redis, SQLite or Postgres and survive restarts, behind one simple interface.
Get started
Tell your AI assistant
“Add lru-cache 11.5.3 (pin it; Node.js 20 or 22+) and wrap the slow lookup in new LRUCache({ max, ttl, fetchMethod }) with import { LRUCache } from 'lru-cache', then read values with await cache.fetch(key).”
Install lru-cache in a project on Node.js 20, or 22 and newer.
npm install lru-cache --saveFrom github.com/isaacs/node-lru-cache/blob/main/package.json
Load it with import or require; both work.
// hybrid module, either works import { LRUCache } from 'lru-cache' // or: const { LRUCache } = require('lru-cache')Create a cache with options that include a limit (max, ttl or maxSize), then save and read items.
const cache = new LRUCache(options) cache.set('key', 'value') cache.get('key') // "value"
Mistakes to avoid
Since version 9 there is no default export, and options are passed as an object.
An unbounded cache is refused; in our run new LRUCache({}) threw "At least one of max, maxSize, or ttl is required".
Setting undefined deletes the key, so has(key) returns false (our run printed false).
In our run an item saved at time 0 never expired, and the cache rechecks the time at most once per millisecond by default.
Object keys match by identity, not by content.
Questions
Does it work with require() and with import?
Yes. The package ships both forms, and since version 9 you take the named LRUCache export.
Can I use objects as keys?
Yes, but only the very same object finds the item again; a copy with the same contents does not.
Do expired items disappear on their own?
Not by default. They count as missing and are deleted when asked for; the ttlAutopurge option removes them early.