# fetch-json-cache

> Caches fetched json. Updates when etag changes and is uses cache regardless if endpoint unreachable. Uses write-file-atomic for safe updates

Latest version **1.7.1** (published 2026-09-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install fetch-json-cache
pnpm add fetch-json-cache
yarn add fetch-json-cache
bun add fetch-json-cache
```

## Health

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

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.7.1 |
| Published | 2026-09-12 |
| First published | 2020-05-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=0.8 |
| Dependencies | 5 |
| Unpacked size | 51.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Kevin Malakoff |
| Maintainers | kmalakoff |
| Keywords | every, async, array, callback |

## Links

- npm: https://www.npmjs.com/package/fetch-json-cache
- Repository: https://github.com/kmalakoff/fetch-json-cache
- Issues: https://github.com/kmalakoff/fetch-json-cache/issues
- npm.io page: https://npm.io/package/fetch-json-cache

## Dependencies (5)

- [queue-cb](https://npm.io/package/queue-cb.md) ^1.0.0
- [temp-suffix](https://npm.io/package/temp-suffix.md) ^1.0.10
- [mkdirp-classic](https://npm.io/package/mkdirp-classic.md) ^0.5.2
- [get-file-compat](https://npm.io/package/get-file-compat.md) ^2.0.0
- [fs-remove-compat](https://npm.io/package/fs-remove-compat.md) ^1.0.0

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.7.1 (latest) — 2026-09-12
- 1.7.0 — 2026-09-03
- 1.6.4 — 2026-08-24
- 1.6.3 — 2026-05-26
- 1.6.2 — 2026-05-26
- 1.6.1 — 2025-12-27
- 1.6.0 — 2025-12-20
- 1.5.0 — 2025-12-18
- 1.4.0 — 2025-12-16
- 1.3.13 — 2025-12-12
- 1.3.12 — 2025-12-12
- 1.3.11 — 2025-12-04
- 1.3.10 — 2025-12-04
- 1.3.9 — 2025-12-04
- 1.3.8 — 2025-12-03
- … 98 more at https://npm.io/package/fetch-json-cache/versions

## README

# fetch-json-cache

Caches fetched JSON and updates it when the endpoint's ETag changes. If a
cached record exists, it reuses that record only when the ETag request fails
with `ENOTFOUND` or the legacy `SSL23_GET_SERVER_HELLO` error. Other errors
propagate, and `{ force: true }` bypasses this fallback.

```sh
npm install fetch-json-cache
```

```js
var Cache = require('fetch-json-cache');
var cache = new Cache('/path/to/cache');
var endpoint = 'https://registry.npmjs.org/fetch-json-cache';

async function run() {
  var json = await cache.get(endpoint);
  console.log(json.name);
  await cache.clear();
}

run().catch(console.error);
```

Pass `{ force: true }` as the second argument to fetch and replace the cached value regardless of its ETag. Use `cache.getSync(endpoint)` to read an existing cached value without making a request.

Callback forms are also available:

```js
cache.get(endpoint, function (err, json) {
  if (err) return console.error(err);
  console.log(json.name);
});
```

Pass a `transform` function in the constructor options to change the parsed JSON before it is stored.

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