Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 3 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

lru-cache

Remember recent results in memory.

UtilitiesNPM

GitHubWebsite

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.md

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

70 / 100
Gid Score, #387 overall
831M
downloads a week, npm
5,920
GitHub stars
47
agent projects use it
lru-cache: downloads per weeknpm, lru-cache 830,690,728
lru-cache: GitHub starsisaacs/node-lru-cache 5,920

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

33 projects, 1.4%
29 projects, 0.9%
16 projects, 0.5%
12 projects, 4.3%
7 projects, 5.0%

Often used with

In 72.3% of its projects
In 66.0% of its projects
In 66.0% of its projects
In 80.9% of its projects
In 61.7% of its projects
In 57.4% of its projects
In 55.3% of its projects
In 57.4% of its projects

More about lru-cache

Funding
  • GitHub Sponsors: https://github.com/isaacs
  • 23 GitHub sponsors

See all

More in Utilities

Alternatives

lru-cache This page

BlueOak-1.0.0Gid 70831M/wk

node-cache

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.

Keyv

Pick Keyv when the cache must live in Redis, SQLite or Postgres and survive restarts, behind one simple interface.

Compare lru-cache with another tool

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).”

  1. Install lru-cache in a project on Node.js 20, or 22 and newer.

    npm install lru-cache --save

    From github.com/isaacs/node-lru-cache/blob/main/package.json

  2. Load it with import or require; both work.

    // hybrid module, either works
    import { LRUCache } from 'lru-cache'
    // or:
    const { LRUCache } = require('lru-cache')
    

    From github.com/isaacs/node-lru-cache/blob/main/README.md

  3. 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"
    

    From github.com/isaacs/node-lru-cache/blob/main/README.md

Mistakes to avoid

import LRU from 'lru-cache'; const cache = new LRU(100)
import { LRUCache } from 'lru-cache'; const cache = new LRUCache({ max: 100 })

Since version 9 there is no default export, and options are passed as an object.

new LRUCache({}) with no limit
Set max (best for speed), maxSize or ttl

An unbounded cache is refused; in our run new LRUCache({}) threw "At least one of max, maxSize, or ttl is required".

cache.set(key, undefined) to remember "nothing found"
Store a marker of your own, such as Symbol('none'), and turn it back into undefined when reading

Setting undefined deletes the key, so has(key) returns false (our run printed false).

A test fake clock that starts at 0 (let myClockTime = 0)
Start the fake clock above 0 and set ttlResolution 0

In our run an item saved at time 0 never expired, and the cache rechecks the time at most once per millisecond by default.

Using a fresh copy of an object as the key to read an item
Keep and reuse the same key object, or use a string key such as an id

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.