npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ai-sdk-cache

v0.1.0

Published

Record/replay cache middleware for the Vercel AI SDK — identical prompts replay from disk instantly, so dev iterations are free and tests run offline and deterministic.

Readme

ai-sdk-cache

npm license

Record/replay cache middleware for the Vercel AI SDK.

You're building a UI over an LLM call. You tweak a margin, hot-reload, and pay for the same completion again. Your test suite hits the provider — so it's slow, flaky, needs secrets in CI, and bills you for the privilege. This middleware fixes both: identical requests replay from disk instantly. Change the prompt, and it's a miss — you get a real response, and it's cached for next time.

import { wrapLanguageModel } from "ai";
import { openai } from "@ai-sdk/openai";
import { cacheMiddleware } from "ai-sdk-cache";

const model = wrapLanguageModel({
  model: openai("gpt-5"),
  middleware: cacheMiddleware({
    enabled: () => process.env.NODE_ENV !== "production",
  }),
});

// Everything downstream is unchanged — and now free to re-run:
const { text } = await generateText({ model, prompt: "…" });

Works with streaming, tools, and structured output — it sits at the SDK's middleware seam, under all of that. Streams are recorded part-by-part as they pass through and replayed as a real stream; only fully-consumed streams are recorded, so an aborted generation never poisons the cache.

Install

npm i -D ai-sdk-cache   # AI SDK v6 ('ai' ^6) is a peer dependency

Deterministic tests, offline CI

Cache entries are plain JSON files under .ai-sdk-cache/ — inspectable, diffable, and safe to commit as fixtures. In CI, replay-only turns any cache miss into a loud failure instead of a surprise API call:

const model = wrapLanguageModel({
  model: openai("gpt-5"),
  middleware: cacheMiddleware({
    mode: process.env.CI ? "replay-only" : "default",
  }),
});

| Mode | Hit | Miss | |---|---|---| | default | replay | call provider, record | | record | call provider, overwrite | call provider, record | | replay-only | replay | throw | | bypass | call provider | call provider |

Refresh fixtures intentionally with mode: "record" (or delete the JSON files).

How keys work

sha256(kind + provider + modelId + params) over a stable stringify (property order doesn't matter). Same model, same messages, same settings → same key. Need to ignore a volatile field? Supply your own:

cacheMiddleware({
  key: ({ type, provider, modelId, params }) =>
    myHash({ type, provider, modelId, params, ignore: "timestamps" }),
});

Stores

  • fsStore(dir) — default; one JSON file per entry under .ai-sdk-cache/.
  • memoryStore() — per-process, no disk; handy in unit tests.
  • Bring your own: { get(key), set(key, value) } — Redis, SQLite, whatever.

Binary payloads (generated files/images as Uint8Array) survive the round trip via tagged base64.

Options

cacheMiddleware({
  store,     // CacheStore — default fsStore(dir)
  dir,       // fs store location — default ".ai-sdk-cache"
  mode,      // "default" | "record" | "replay-only" | "bypass"
  enabled,   // boolean | () => boolean — gate without rewiring the model
  key,       // custom cache-key function
});

Heads-up: this is a development and testing tool. For production response caching you want TTLs, invalidation, and shared storage — different problem, different tradeoffs.

License

MIT © Binaya Dhakal