# @graphile/lru

> Extremely simple zero-dependencies ES6 LRU (you probably want lru-cache instead)

Latest version **5.0.1** (published 2026-10-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @graphile/lru
pnpm add @graphile/lru
yarn add @graphile/lru
bun add @graphile/lru
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; popular repo.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 5.0.1 |
| Published | 2026-10-30 |
| First published | 2019-05-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=22 |
| Dependencies | 1 |
| Unpacked size | 12.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 12934 |
| Author | Benjie Gillam |
| Maintainers | benjie, mattbretl |
| Keywords | lru, graphile, graphite |

## Links

- npm: https://www.npmjs.com/package/@graphile/lru
- Repository: https://github.com/graphile/crystal
- Homepage: https://github.com/graphile/crystal/tree/main/utils/lru
- Issues: https://github.com/graphile/crystal/issues
- npm.io page: https://npm.io/package/@graphile/lru

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.8.1

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 5.0.1 (latest) — 2026-10-30
- 5.0.1-aardvark.next-20260928202932 (snapshot-next) — 2026-09-28
- 5.0.0-rc.5 (rc) — 2026-03-10
- 5.0.0-beta.4 (beta) — 2025-06-07
- 5.0.0-alpha.2 (alpha) — 2023-05-19
- 5.0.0-alpha.1 (prealpha) — 2023-04-26
- 4.11.0 (next) — 2021-01-20
- 5.0.1-aardvark.next-20260925164249 — 2026-09-25
- 5.0.1-aardvark.next-20260922224416 — 2026-09-22
- 5.0.1-aardvark.next-20260919185130 — 2026-09-19
- 5.0.1-aardvark.next-20260918085327 — 2026-09-18
- 5.0.1-aardvark.next-20260910230054 — 2026-09-10
- 5.0.1-aardvark.next-20260907131448 — 2026-09-07
- 5.0.1-aardvark.next-20260902182429 — 2026-09-02
- 5.0.1-aardvark.next-20260902153400 — 2026-09-02
- … 27 more at https://npm.io/package/@graphile/lru/versions

## README

# @graphile/lru

**You probably want [lru-cache](https://github.com/isaacs/node-lru-cache)
instead.**

This is an obsessively optimized LRU cache for Node.js, it forgoes features in
favour of performance, and is very marginally faster than node-lru-cache v6 in
certain circumstances (namely those that we care about inside the Graphile
internals). A performance comparison versus node-lru-cache v7 has not yet been
performed.

## Usage

```js
import LRU from "@graphile/lru";

// Construct an LRU cache
const lru = new LRU({
  // Maximum number of items to store (required)
  maxLength: 500, // Must be an integer at least 2

  // Optional callback to handle when a value is removed (both when LRU becomes
  // full and when LRU is reset)
  dispose(key, value) {
    console.log(`Disposing of key '${key}' with value '${inspect(value)}'`);
  },
});

const ANY_KEY_HERE = { foo: "bar" };
const ANY_VALUE_HERE = { randomNumber: () => 4 };
// Store a value
lru.set(ANY_KEY_HERE, ANY_VALUE_HERE);

// Retrieve a value
const value = lru.get(ANY_KEY_HERE);

// Clear the cache
lru.reset();
```

## Considering a pull request?

Pull requests that add features that aren't required by the Graphile suite are
unlikely to be entertained - use node-lru-cache instead!

Pull requests that improve performance should come with benchmarks, benchmark
scripts and explanation of technique. And if you pull it off without breaking
anything - YES PLEASE.

Pull requests that add documentation are welcome.

---
_Source: https://npm.io/package/@graphile/lru · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
