# @arcjet/cache

> Arcjet cache interface and implementations

Latest version **1.14.1** (published 2026-10-07) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @arcjet/cache
pnpm add @arcjet/cache
yarn add @arcjet/cache
bun add @arcjet/cache
```

## Health

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

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.14.1 |
| Published | 2026-10-07 |
| First published | 2025-05-28 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.21.0 <23 \|\| >=24.5.0 |
| Dependencies | 0 |
| Unpacked size | 17.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 685 |
| Author | Arcjet |
| Maintainers | quinn-arcjet, davidmytton |
| Keywords | arcjet, cache, util, utility |

## Links

- npm: https://www.npmjs.com/package/@arcjet/cache
- Repository: https://github.com/arcjet/arcjet-js
- Homepage: https://arcjet.com
- Issues: https://github.com/arcjet/arcjet-js/issues
- npm.io page: https://npm.io/package/@arcjet/cache

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.14.1 (latest) — 2026-10-07
- 1.10.0-rc.1 (rc) — 2026-08-07
- 1.14.0 — 2026-10-01
- 1.13.0 — 2026-09-16
- 1.12.0 — 2026-09-08
- 1.11.0 — 2026-08-26
- 1.10.0 — 2026-08-11
- 1.10.0-rc.0 — 2026-08-04
- 1.9.1 — 2026-07-15
- 1.9.0 — 2026-07-15
- 1.8.0 — 2026-07-07
- 1.8.0-rc.0 — 2026-07-07
- 1.7.0 — 2026-07-06
- 1.7.0-rc.1 — 2026-07-06
- 1.7.0-rc.0 — 2026-07-03
- … 21 more at https://npm.io/package/@arcjet/cache/versions

## README

<a href="https://arcjet.com" target="_arcjet-home">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/logo/arcjet-dark-lockup-voyage-horizontal.svg">
    <img src="https://arcjet.com/logo/arcjet-light-lockup-voyage-horizontal.svg" alt="Arcjet Logo" height="128" width="auto">
  </picture>
</a>

# `@arcjet/cache`

<p>
  <a href="https://www.npmjs.com/package/@arcjet/cache">
    <picture>
      <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Fcache?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
      <img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Fcache?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
    </picture>
  </a>
</p>

[Arcjet][arcjet] cache interface and implementations.

- [npm package (`@arcjet/cache`)](https://www.npmjs.com/package/@arcjet/cache)
- [GitHub source code (`cache/` in `arcjet/arcjet-js`)](https://github.com/arcjet/arcjet-js/tree/main/cache)

## What is this?

This is an internal utility to help us cache some things in memory.

## When should I use this?

This is an internal Arcjet package not designed for public use.
See our [_Get started_ guide][arcjet-get-started] for how to use Arcjet in your
application.

## Install

This package is ESM only.
Install with npm in Node.js:

```sh
npm install @arcjet/cache
```

## Use

```ts
import { setTimeout } from "node:timers/promises";
import { MemoryCache } from "@arcjet/cache";

const cache = new MemoryCache<string>();

cache.set("namespace", "key", "value", 2);

console.log(await cache.get("namespace", "key"));
// => [ 'value', 2 ]

await setTimeout(2001);

console.log(await cache.get("namespace", "key"));
// => [ undefined, 0 ]
```

## API

### `MemoryCache#constructor()`

Instantiate the `MemoryCache` using `new MemoryCache()` without any arguments.

### `MemoryCache#get(namespace: string, key: string): Promise<[T | undefined, number]>`

Attempts to retrieve a value from the cache. If a value exists, it will be
returned with the remaining time-to-live (in seconds).

Non-string arguments will cause the returned promise to reject.

### `MemoryCache#set(namespace: string, key: string, value: T, ttl: number): void`

Makes a best attempt at storing the value provided until the time-to-live
specified.

Non-string arguments will cause the function to throw.

## License

[Apache License, Version 2.0][apache-license] © [Arcjet Labs, Inc.][arcjet]

[arcjet]: https://arcjet.com
[arcjet-get-started]: https://docs.arcjet.com/get-started
[apache-license]: http://www.apache.org/licenses/LICENSE-2.0

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