# JavaScript caching libraries

JavaScript caching libraries keep computed or fetched results in memory or storage for reuse. Each cache evicts entries once they pass a limit on count, total size, or time to live. These libraries hold the API responses, rendered fragments, and database results that servers, build tools, and CLIs would otherwise recompute.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [LRUCache](#lru-cache) | 3.1B | 5.9K | Sep 2026 | BlueOak-1.0.0 |
| [Keyv](#keyv) | 866.0M | Not on GitHub | Oct 2026 | MIT |
| [FlatCache](#flat-cache) | 796.0M | Not on GitHub | Jun 2026 | MIT |
| [QuickLRU](#quick-lru) | 238.8M | 775 | Nov 2026 | MIT |
| [Cacheable](#cacheable) | 161.0M | Not on GitHub | Jun 2026 | MIT |
| [CacheableMemory](#cacheable-memory) | 158.3M | Not on GitHub | Jun 2026 | MIT |
| [TTLCache](#isaacs-ttlcache) | 98.8M | Not on GitHub | May 2026 | BlueOak-1.0.0 |

Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[LRUCache](#lru-cache) has the most monthly downloads in this comparison, at 3.1B.

## Capabilities

| Library | LRU eviction | Disk snapshots | Async get/set |
| --- | --- | --- | --- |
| [LRUCache](#lru-cache) | Yes | No | No |
| [Keyv](#keyv) | Via plugin | No | Yes |
| [FlatCache](#flat-cache) | Yes | Yes | No |
| [QuickLRU](#quick-lru) | Yes | No | No |
| [Cacheable](#cacheable) | Yes | No | Yes |
| [CacheableMemory](#cacheable-memory) | Yes | No | No |
| [TTLCache](#isaacs-ttlcache) | No | No | No |

## Libraries

### LRUCache

[GitHub](https://github.com/isaacs/node-lru-cache) · [npm](https://www.npmjs.com/package/lru-cache) · [Docs](https://cdn.jsdelivr.net/npm/lru-cache@11.5.3/README.md)

Stores recently used entries with configurable size bounds, expiration, and asynchronous loading.

- Downloads / mo: 3.1B
- Stars: 5.9K
- Last release: 11.5.3
- License: BlueOak-1.0.0
- Capabilities: [From the LRUCache docs](https://cdn.jsdelivr.net/npm/lru-cache@11.5.3/README.md)

**Strengths**

- **Bounds the entry count.** Set max to retain a fixed number of recently accessed entries.
- **Loads values asynchronously.** Set fetchMethod and call fetch for asynchronous cache loading.

**Watch out for**

- **Expired entries wait for access.** Enable ttlAutopurge when stale entries need proactive removal.
- **Undefined values are not stored.** Use a sentinel when undefined is a meaningful cached result.

```sh
npm install lru-cache@11.5.3
```

**npm/hosted-git-info** (240 stars)

[npm/hosted-git-info](https://github.com/npm/hosted-git-info) 

```javascript
static fromUrl (giturl, opts) {
  if (typeof giturl !== 'string') {
    return
  }

  const key = giturl + JSON.stringify(opts || {})

  if (!cache.has(key)) {
    const hostArgs = fromUrl(giturl, opts, {
      gitHosts: GitHost.#gitHosts,
      protocols: GitHost.#protocols,
    })
    cache.set(key, hostArgs ? new GitHost(...hostArgs) : null)
  }

  return cache.get(key) ?? undefined
}

```

[lib/index.js](https://github.com/npm/hosted-git-info/blob/477bef8d76264411d911c860c8e6ca9b1e22a28d/lib/index.js#L62-L78) · [More projects using LRUCache →](https://dashboard.exa.ai/playground/search?q=JavaScript%20applications%20using%20lru-cache%20for%20caching%20repeated%20work%2C%20bounded%20entries%2C%20expiration%20and%20storage%20configuration&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
import { LRUCache } from 'lru-cache';

const cache = new LRUCache({ max: 1000 });
cache.set('key', 'value');

```

From [README.md](https://cdn.jsdelivr.net/npm/lru-cache@11.5.3/README.md)

### Keyv

[GitHub](https://github.com/jaredwray/keyv) · [npm](https://www.npmjs.com/package/keyv) · [Docs](https://cdn.jsdelivr.net/npm/keyv@6.1.0/README.md)

Stores key-value pairs with namespaces and TTL behind an async API, in memory or through storage adapters.

- Downloads / mo: 866.0M
- Last release: 6.1.0
- License: MIT
- Capabilities: [From the Keyv docs](https://cdn.jsdelivr.net/npm/keyv@6.1.0/README.md)

```sh
npm install keyv@6.1.0
```

**jaredwray/cacheable** (2.0K stars)

[jaredwray/cacheable](https://github.com/jaredwray/cacheable) 

```javascript
const get = async (options_: any) => {
	await Promise.resolve();
	const cacheEntry = options_.cache
		? await this.cache.get(key)
		: undefined;

	if (cacheEntry === undefined && !options_.forceRefresh) {
		makeRequest(options_);
		return;
	}

	const policy = CachePolicy.fromObject(
		(cacheEntry as CacheValue).cachePolicy,
	);
	if (
		policy.satisfiesWithoutRevalidation(options_) &&
		!options_.forceRefresh
	) {
		const headers = convertHeaders(policy.responseHeaders());
		const bodyBuffer = (cacheEntry as CacheValue).body;
		const body = Buffer.from(bodyBuffer as string);
		const response: any = new Response({
			statusCode: (cacheEntry as CacheValue).statusCode,
			headers,
			body,
			url: (cacheEntry as CacheValue).url,
		});
		response.cachePolicy = policy;
		response.fromCache = true;
		ee.emit("response", response);
		if (typeof callback === "function") {
			callback(response);
		}
	} else if (
		policy.satisfiesWithoutRevalidation(options_) &&
		Date.now() >= policy.timeToLive() &&
		options_.forceRefresh
	) {
		await this.cache.delete(key);
		options_.headers = policy.revalidationHeaders(options_);
		makeRequest(options_);
	} else {
		revalidate = cacheEntry;
		options_.headers = policy.revalidationHeaders(options_);
		makeRequest(options_);
	}
};

```

[packages/cacheable-request/src/index.ts](https://github.com/jaredwray/cacheable/blob/b7611eb9196ea89609b58b95b0cba9e7f0ac52f5/packages/cacheable-request/src/index.ts#L268-L314) · [More projects using Keyv →](https://dashboard.exa.ai/playground/search?q=keyv%20GitHub%20projects)

**Quickstart**

```javascript
import { Keyv } from 'keyv';

const cache = new Keyv();
await cache.set('key', 'value');

```

From [README.md](https://cdn.jsdelivr.net/npm/keyv@6.1.0/README.md)

### FlatCache

[GitHub](https://github.com/jaredwray/flat-cache) · [npm](https://www.npmjs.com/package/flat-cache) · [Docs](https://cdn.jsdelivr.net/npm/flat-cache@6.1.23/README.md)

Caches values in memory and saves them to a file, with TTL and LRU controls.

- Downloads / mo: 796.0M
- Last release: 6.1.23
- License: MIT
- Capabilities: [From the FlatCache docs](https://cdn.jsdelivr.net/npm/flat-cache@6.1.23/README.md)

```sh
npm install flat-cache@6.1.23
```

**samestrin/llm-interface** (123 stars)

[samestrin/llm-interface](https://github.com/samestrin/llm-interface) 

```javascript
async getFromCache(key) {
  const hashedKey = this.getCacheFilePath(key);
  try {
    if (this.cacheType === 'flat-cache') {
      const cachedData = this.cacheInstance.getKey(hashedKey);
      if (cachedData && cachedData.ttl && Date.now() > cachedData.ttl) {
        this.cacheInstance.removeKey(hashedKey);
        this.cacheInstance.save(true);
        return null;
      }
      return cachedData ? cachedData.data : null;
    } else if (this.cacheType === 'cache-manager') {
      if (
        typeof this.cacheInstance?.store?.get !== 'function' &&
        typeof this.cacheInstance?.get !== 'function'
      ) {
        await this.loadCacheInstance();
      }

      if (typeof this.cacheInstance?.store?.get === 'function') {
        return await this.cacheInstance.store.get(hashedKey);
      } else if (typeof this.cacheInstance?.get === 'function') {
        return await this.cacheInstance.get(hashedKey);
      } else {
        throw new CacheError('Cache manage not available');
      }
    } else if (this.cacheType === 'simple-cache') {
      return await this.cacheInstance.getFromCache(hashedKey);
    } else if (this.cacheType === 'memory-cache') {
      return this.cacheInstance.get(hashedKey);
    }
  } catch (error) {
    console.error(error);
    return null;
  }
}

```

[src/utils/cacheManager.js](https://github.com/samestrin/llm-interface/blob/e0ffa163679a998a5e3692779a91dd2dad6ebe96/src/utils/cacheManager.js#L93-L128) · [More projects using FlatCache →](https://dashboard.exa.ai/playground/search?q=flat-cache%20GitHub%20projects)

**Quickstart**

```javascript
import { FlatCache } from 'flat-cache';

const cache = new FlatCache();
cache.setKey('key', 'value');
cache.save();

```

From [README.md](https://cdn.jsdelivr.net/npm/flat-cache@6.1.23/README.md)

### QuickLRU

[GitHub](https://github.com/sindresorhus/quick-lru) · [npm](https://www.npmjs.com/package/quick-lru) · [Docs](https://cdn.jsdelivr.net/npm/quick-lru@8.0.0/readme.md)

Provides a Map-based in-memory cache with approximate LRU eviction and optional expiration.

- Downloads / mo: 238.8M
- Stars: 775
- Last release: 8.0.0
- License: MIT
- Capabilities: [From the QuickLRU docs](https://cdn.jsdelivr.net/npm/quick-lru@8.0.0/readme.md)

**Strengths**

- **Fits Map-based application code.** Use a Map subclass with familiar cache access methods.
- **Supports per-entry expiration.** Set maxAge globally or specify expiration for individual entries.

**Watch out for**

- **Size can exceed the target.** Stored entries can exceed maxSize before batch eviction.
- **Expired entries are removed lazily.** Removal waits for a read, iteration, or eviction.

```sh
npm install quick-lru@8.0.0
```

**sanity-io/sanity** (6.4K stars)

[sanity-io/sanity](https://github.com/sanity-io/sanity) 

```javascript
function createLRUCache<T>(options: {maxSize: number}): SWRCache<T> {
  const lru = new QuickLRU<string, {value: T}>(options)
  return {
    get(key: string) {
      const entry = lru.get(key)
      if (!entry) {
        throw new Error(`Key not found in LRU cache: ${key}`)
      }
      return entry.value
    },
    set(key: string, value: T) {
      lru.set(key, {value})
    },
    delete(key: string) {
      lru.delete(key)
    },
    has(key: string) {
      return lru.has(key)
    },
  }
}

```

[packages/sanity/src/core/util/rxSwr.ts](https://github.com/sanity-io/sanity/blob/d50d96424b3978196c75d0a291d9725ec85fa67f/packages/sanity/src/core/util/rxSwr.ts#L50-L70) · [More projects using QuickLRU →](https://dashboard.exa.ai/playground/search?q=JavaScript%20applications%20using%20quick-lru%20for%20caching%20repeated%20work%2C%20bounded%20entries%2C%20expiration%20and%20storage%20configuration&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
import QuickLRU from 'quick-lru';

const cache = new QuickLRU({ maxSize: 1000 });
cache.set('key', 'value');

```

From [readme.md](https://cdn.jsdelivr.net/npm/quick-lru@8.0.0/readme.md)

### Cacheable

[GitHub](https://github.com/jaredwray/cacheable) · [npm](https://www.npmjs.com/package/cacheable) · [Docs](https://cdn.jsdelivr.net/npm/cacheable@2.5.0/README.md)

Coordinates a primary and a secondary cache built on Keyv, with TTL, tags, and statistics.

- Downloads / mo: 161.0M
- Last release: 2.5.0
- License: MIT
- Capabilities: [From the Cacheable docs](https://cdn.jsdelivr.net/npm/cacheable@2.5.0/README.md)

```sh
npm install cacheable@2.5.0
```

**webstreamr/webstreamr** (167 stars)

[webstreamr/webstreamr](https://github.com/webstreamr/webstreamr) 

```javascript
public async handle(ctx: Context, url: URL, meta?: Meta, allowLazy?: boolean): Promise<UrlResult[]> {
  const extractor = this.extractors.find(extractor => !isExtractorDisabled(ctx.config, extractor) && extractor.supports(ctx, url));
  if (!extractor) {
    return [];
  }

  const normalizedUrl = extractor.normalize(url);
  const cacheKey = this.determineCacheKey(ctx, extractor, normalizedUrl);

  const storedDataRaw = await this.urlResultCache.getRaw<UrlResult[]>(cacheKey);
  const expires = storedDataRaw?.expires;
  if (storedDataRaw && expires) {
    const ttl = expires - Date.now();

    /* istanbul ignore if */
    if (ttl > 0) {
      return (storedDataRaw.value as UrlResult[]).map(urlResult => ({ ...urlResult, ttl, url: new URL(urlResult.url) }));
    }
  }

  const lazyUrlResults = await this.lazyUrlResultCache.get<UrlResult[]>(normalizedUrl.href) ?? [];

  /* istanbul ignore next */
  if (
    lazyUrlResults.length && allowLazy && !extractor.viaMediaFlowProxy
    && lazyUrlResults.every(urlResult => urlResult.format !== Format.hls) // related to Android issues, e.g. https://github.com/Stremio/stremio-bugs/issues/1574 or https://github.com/Stremio/stremio-bugs/issues/1579
  ) {
    // generate lazy extract urls
    return lazyUrlResults.map((urlResult, index) => {
      const extractUrl = new URL(`${envGet('PROTOCOL')}:${envGet('HOST')}/extract/`);

      extractUrl.searchParams.set('index', `${index}`);
      extractUrl.searchParams.set('url', url.href);

      return { ...urlResult, url: extractUrl };
    });
  }

  this.logger.info(`Extract ${url} using ${extractor.id} extractor`, ctx);

  const mergedMeta: Meta = { ...meta, ...lazyUrlResults[0]?.meta };
  const urlResults = await extractor.extract(ctx, normalizedUrl, { extractorId: extractor.id, ...mergedMeta });

  if (!Object.keys(mergedMeta).length || urlResults.some(urlResult => urlResult.error)) {
    await this.urlResultCache.delete(cacheKey);
    await this.lazyUrlResultCache.delete(normalizedUrl.href);

    return urlResults;
  }

  const ttl = urlResults.length ? extractor.ttl : 43200000; // 12h

  await this.urlResultCache.set<UrlResult[]>(cacheKey, urlResults, ttl);

  if (extractor.id !== 'external') {
    await this.lazyUrlResultCache.set<UrlResult[]>(normalizedUrl.href, urlResults, 2629800000); // 1 month
  }

  return urlResults;
};

```

[src/extractor/ExtractorRegistry.ts](https://github.com/webstreamr/webstreamr/blob/720c9bb651a7a06a62f5f3636099b5cfb7506bcb/src/extractor/ExtractorRegistry.ts#L40-L99) · [More projects using Cacheable →](https://dashboard.exa.ai/playground/search?q=cacheable%20GitHub%20projects)

**Quickstart**

```javascript
import { Cacheable } from 'cacheable';

const cache = new Cacheable();
await cache.set('key', 'value');

```

From [README.md](https://cdn.jsdelivr.net/npm/cacheable@2.5.0/README.md)

### CacheableMemory

[GitHub](https://github.com/jaredwray/cacheable) · [npm](https://www.npmjs.com/package/@cacheable/memory) · [Docs](https://cdn.jsdelivr.net/npm/@cacheable/memory@2.2.0/README.md)

Keeps values in a synchronous in-memory store with an optional LRU size limit and TTL expiry.

- Downloads / mo: 158.3M
- Last release: 2.2.0
- License: MIT
- Capabilities: [From the CacheableMemory docs](https://cdn.jsdelivr.net/npm/@cacheable/memory@2.2.0/README.md)

```sh
npm install @cacheable/memory@2.2.0
```

**webstreamr/webstreamr** (167 stars)

[webstreamr/webstreamr](https://github.com/webstreamr/webstreamr) 

```javascript
public constructor(logger: winston.Logger, extractors: Extractor[]) {
  this.logger = logger;
  this.extractors = extractors;

  this.urlResultCache = new Cacheable({
    nonBlocking: true,
    primary: new Keyv({ store: new CacheableMemory({ lruSize: 1024 }) }),
    secondary: createKeyvSqlite('extractor-cache'),
    stats: true,
  });

  this.lazyUrlResultCache = new Cacheable({
    nonBlocking: true,
    primary: new Keyv({ store: new CacheableMemory({ lruSize: 1024 }) }),
    secondary: createKeyvSqlite('extractor-lazy-cache'),
    stats: true,
  });
}

```

[src/extractor/ExtractorRegistry.ts](https://github.com/webstreamr/webstreamr/blob/720c9bb651a7a06a62f5f3636099b5cfb7506bcb/src/extractor/ExtractorRegistry.ts#L14-L31) · [More projects using CacheableMemory →](https://dashboard.exa.ai/playground/search?q=%40cacheable/memory%20GitHub%20projects)

**Quickstart**

```javascript
import { CacheableMemory } from '@cacheable/memory';

const cache = new CacheableMemory();
cache.set('key', 'value');

```

From [README.md](https://cdn.jsdelivr.net/npm/@cacheable/memory@2.2.0/README.md)

### TTLCache

[GitHub](https://github.com/isaacs/ttlcache) · [npm](https://www.npmjs.com/package/@isaacs/ttlcache) · [Docs](https://cdn.jsdelivr.net/npm/@isaacs/ttlcache@2.1.5/README.md)

Expires every entry after its TTL and evicts the soonest-expiring entries when the cache is full.

- Downloads / mo: 98.8M
- Last release: 2.1.5
- License: BlueOak-1.0.0
- Capabilities: [From the TTLCache docs](https://cdn.jsdelivr.net/npm/@isaacs/ttlcache@2.1.5/README.md)

```sh
npm install @isaacs/ttlcache@2.1.5
```

**Quickstart**

```javascript
import { TTLCache } from '@isaacs/ttlcache';

const cache = new TTLCache({ max: 10000, ttl: 1000 });
cache.set('key', 'value');

```

From [README.md](https://cdn.jsdelivr.net/npm/@isaacs/ttlcache@2.1.5/README.md) · [Find projects using TTLCache →](https://dashboard.exa.ai/playground/search?q=%40isaacs/ttlcache%20GitHub%20projects)

## FAQ

### What is an LRU cache in JavaScript?

An LRU (least recently used) cache keeps a bounded number of entries and evicts the entry read longest ago when it fills. [LRUCache](#lru-cache) and [QuickLRU](#quick-lru) work this way, while [TTLCache](#isaacs-ttlcache) evicts the soonest-expiring entries instead.

### Does an entry TTL remove stale values immediately?

lru-cache removes expired values when they are read, unless ttlAutopurge enables preemptive deletion. quick-lru removes expired values lazily on reads, iteration, or eviction.

### Does QuickLRU enforce a strict maxSize entry count?

Its target maxSize can be exceeded internally even though the reported size is capped.

### Can lru-cache store undefined as a cached result?

No. Storing undefined removes the key. A sentinel value can stand in for an intentionally empty result.

### Can lru-cache load a value asynchronously?

Its fetchMethod option supplies the asynchronous cache.fetch workflow.

### How does Keyv store data in Redis?

[Keyv](#keyv) keeps data in an in-memory Map by default and reaches Redis or other databases through storage adapters.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best JavaScript caching libraries lru-cache quick-lru node-cache cache-manager code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
