{
 "kind": "tool",
 "slug": "lru-cache",
 "path": "tools/lru-cache/",
 "name": "lru-cache",
 "maker": null,
 "density": "full",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "Utilities",
   "tools/utilities/"
  ]
 ],
 "lead": "Remember recent results in memory.",
 "chips": [
  {
   "label": "Utilities",
   "path": "tools/utilities/"
  },
  {
   "label": "NPM"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "npm install lru-cache"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/isaacs/node-lru-cache"
  },
  {
   "label": "Website",
   "href": "https://github.com/isaacs/node-lru-cache#readme"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "BlueOak-1.0.0",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": "Each contributor licenses you to do everything with this software that would otherwise infringe that contributor's copyright in it.",
   "note": "The Blue Oak license lets you do everything with the code, also in paid products.",
   "src": "https://github.com/isaacs/node-lru-cache/blob/main/LICENSE.md"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Maintained",
   "status": "yes",
   "sub": "Last change Sep 18, 2026",
   "note": "",
   "src": "https://github.com/isaacs/node-lru-cache"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "47 projects",
   "status": "info",
   "sub": "#27 of 408 in its category",
   "note": "Dependency in 47 public GitHub projects set up for AI coding agents that we scanned (0.8%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Install only",
   "status": "info",
   "sub": null,
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": null
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily; card checked Nov 10, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What lru-cache does",
   "parts": [
    {
     "t": "prose",
     "text": "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."
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "Stop repeating slow lookups",
       "text": "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.",
       "idea": false
      },
      {
       "title": "Keep memory use bounded",
       "text": "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.",
       "idea": false
      },
      {
       "title": "Answers that expire",
       "text": "Exchange rates or a list of open slots may be reused for a few minutes, then must be looked up fresh.",
       "idea": false
      },
      {
       "title": "Cap the cache by size",
       "text": "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.",
       "idea": false
      },
      {
       "title": "Clean up what falls out",
       "text": "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.",
       "idea": false
      },
      {
       "title": "Test expiry with a fake clock",
       "text": "Your tests move a fake clock forward instead of waiting, to check that old answers really expire.",
       "idea": false
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "lru-cache popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "70",
       "of": "/ 100",
       "l": "Gid Score, #387 overall"
      },
      {
       "n": "831M",
       "l": "downloads a week, npm"
      },
      {
       "n": "5,920",
       "l": "GitHub stars"
      },
      {
       "n": "47",
       "l": "agent projects use it"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How lru-cache is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "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%)."
     ]
    },
    {
     "t": "h3",
     "text": "By coding agent"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "33 projects, 1.4%",
       "v": "Cursor",
       "path": "agents/cursor/"
      },
      {
       "l": "29 projects, 0.9%",
       "v": "Claude Code",
       "path": "agents/claude-code/"
      },
      {
       "l": "16 projects, 0.5%",
       "v": "GitHub Copilot",
       "path": "agents/github-copilot/"
      },
      {
       "l": "12 projects, 4.3%",
       "v": "Devin Desktop",
       "path": "agents/devin-desktop/"
      },
      {
       "l": "7 projects, 5.0%",
       "v": "Kiro",
       "path": "agents/kiro/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 72.3% of its projects",
       "v": "chalk",
       "path": "tools/chalk/"
      },
      {
       "l": "In 66.0% of its projects",
       "v": "Anthropic SDK",
       "path": "tools/anthropic-ai/"
      },
      {
       "l": "In 66.0% of its projects",
       "v": "Fuse.js",
       "path": "tools/fuse-js/"
      },
      {
       "l": "In 80.9% of its projects",
       "v": "Zod",
       "path": "tools/zod/"
      },
      {
       "l": "In 61.7% of its projects",
       "v": "dotenv",
       "path": "tools/dotenv/"
      },
      {
       "l": "In 57.4% of its projects",
       "v": "Express",
       "path": "tools/express/"
      },
      {
       "l": "In 55.3% of its projects",
       "v": "Commander",
       "path": "tools/commander/"
      },
      {
       "l": "In 57.4% of its projects",
       "v": "tsx",
       "path": "tools/tsx/"
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "usage",
   "h2": "More about lru-cache",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "Funding",
       "path": "tools/funding/",
       "items": [
        "GitHub Sponsors: https://github.com/isaacs",
        "23 GitHub sponsors"
       ]
      },
      {
       "title": "More in Utilities",
       "path": "tools/utilities/",
       "items": [
        {
         "text": "clsx",
         "path": "tools/clsx/"
        },
        {
         "text": "date-fns",
         "path": "tools/date-fns/"
        },
        {
         "text": "PyYAML",
         "path": "tools/pyyaml/"
        },
        {
         "text": "uuid",
         "path": "tools/uuid/"
        },
        {
         "text": "yaml",
         "path": "tools/yaml/"
        },
        {
         "text": "js-yaml",
         "path": "tools/js-yaml/"
        },
        {
         "text": "glob",
         "path": "tools/glob/"
        },
        {
         "text": "Lodash",
         "path": "tools/lodash/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "lru-cache",
       "me": true,
       "facts": [
        "BlueOak-1.0.0",
        "Gid 70",
        "831M/wk"
       ]
      },
      {
       "name": "node-cache",
       "why": "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.",
       "path": "tools/node-cache/",
       "facts": []
      },
      {
       "name": "Keyv",
       "why": "Pick Keyv when the cache must live in Redis, SQLite or Postgres and survive restarts, behind one simple interface.",
       "path": "tools/keyv/",
       "facts": []
      }
     ],
     "more": "Compare lru-cache with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "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)."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Install lru-cache in a project on Node.js 20, or 22 and newer.",
       "code": "npm install lru-cache --save",
       "src": "https://github.com/isaacs/node-lru-cache/blob/main/package.json"
      },
      {
       "text": "Load it with import or require; both work.",
       "code": "// hybrid module, either works\nimport { LRUCache } from 'lru-cache'\n// or:\nconst { LRUCache } = require('lru-cache')\n",
       "src": "https://github.com/isaacs/node-lru-cache/blob/main/README.md"
      },
      {
       "text": "Create a cache with options that include a limit (max, ttl or maxSize), then save and read items.",
       "code": "const cache = new LRUCache(options)\n\ncache.set('key', 'value')\ncache.get('key') // \"value\"\n",
       "src": "https://github.com/isaacs/node-lru-cache/blob/main/README.md"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "import LRU from 'lru-cache'; const cache = new LRU(100)",
       "fix": "import { LRUCache } from 'lru-cache'; const cache = new LRUCache({ max: 100 })",
       "why": "Since version 9 there is no default export, and options are passed as an object."
      },
      {
       "dont": "new LRUCache({}) with no limit",
       "fix": "Set max (best for speed), maxSize or ttl",
       "why": "An unbounded cache is refused; in our run new LRUCache({}) threw \"At least one of max, maxSize, or ttl is required\"."
      },
      {
       "dont": "cache.set(key, undefined) to remember \"nothing found\"",
       "fix": "Store a marker of your own, such as Symbol('none'), and turn it back into undefined when reading",
       "why": "Setting undefined deletes the key, so has(key) returns false (our run printed false)."
      },
      {
       "dont": "A test fake clock that starts at 0 (let myClockTime = 0)",
       "fix": "Start the fake clock above 0 and set ttlResolution 0",
       "why": "In our run an item saved at time 0 never expired, and the cache rechecks the time at most once per millisecond by default."
      },
      {
       "dont": "Using a fresh copy of an object as the key to read an item",
       "fix": "Keep and reuse the same key object, or use a string key such as an id",
       "why": "Object keys match by identity, not by content."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "Does it work with require() and with import?",
       "a": "Yes. The package ships both forms, and since version 9 you take the named LRUCache export.",
       "evidence": {
        "url": "https://github.com/isaacs/node-lru-cache/blob/main/README.md",
        "quote": "Named export only, no default export."
       }
      },
      {
       "q": "Can I use objects as keys?",
       "a": "Yes, but only the very same object finds the item again; a copy with the same contents does not.",
       "evidence": {
        "url": "https://github.com/isaacs/node-lru-cache/blob/main/README.md",
        "quote": "A similar object with same keys/values won't work"
       }
      },
      {
       "q": "Do expired items disappear on their own?",
       "a": "Not by default. They count as missing and are deleted when asked for; the ttlAutopurge option removes them early.",
       "evidence": {
        "url": "https://github.com/isaacs/node-lru-cache/blob/main/README.md",
        "quote": "Note that, even when tracking item `ttl`, items are _not_ preemptively deleted when they become stale, unless `ttlAutopurge` is enabled."
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "npm lru-cache"
  ],
  [
   "Category",
   "Utilities"
  ],
  [
   "License",
   "BlueOak-1.0.0"
  ],
  [
   "Gid Score",
   "70.0"
  ],
  [
   "Rank in category",
   "#27 of 408"
  ],
  [
   "GitHub",
   "isaacs/node-lru-cache"
  ],
  [
   "Last change",
   "Sep 18, 2026"
  ]
 ],
 "good": [
  "Expiry is a soft rule: expired items count as missing and are removed when they are next asked for, not right away.",
  "It cannot store an empty (undefined) value; saving one deletes the item instead.",
  "Extra features such as size limits, expiry and clean-up functions make it a bit slower; turn them on only when needed."
 ],
 "checked_line": "Read by AgentGid from 5 official pages, card checked Nov 10, 2026; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/isaacs.png"
}