Skip to main content

Store and expire data in Runtime Cache

Use getCache() for shared key/value cache across function isolates, with tags and plan quotas.

Runtime Cache is a deployment-scoped key/value store shared across function isolates. Use it for computed fragments, rate-limit counters, and other short-lived data that does not belong in your primary database. On Easel it implements the same getCache() contract as @vercel/functions.

For complete HTTP responses at the edge, use CDN caching instead.

Prerequisites

Your deployment must receive platform Runtime Cache env (RUNTIME_CACHE_ENDPOINT and RUNTIME_CACHE_HEADERS). Easel injects those on deploy for supported runtimes.

Using Runtime Cache

Pick your stack. Both paths share the same platform store and tag clock.

app/products/[id]/page.tsx
import { cacheLife, cacheTag } from "next/cache";

async function getProduct(id: string) {
  "use cache: remote";
  cacheTag(`product-${id}`, "products");
  cacheLife({ expire: 3600 });
  return loadProduct(id);
}

export default async function Page({
  params,
}: {
  params: Promise<{ id: string }>;
}) {
  const { id } = await params;
  const product = await getProduct(id);
  return <pre>{JSON.stringify(product, null, 2)}</pre>;
}

You can also call getCache() from Next.js Route Handlers the same way as the Other example.

Expire by tag

app/actions.ts
"use server";

import { revalidateTag } from "next/cache";

export async function updateProduct(id: string) {
  await saveProduct(id);
  revalidateTag(`product-${id}`);
  revalidateTag("products");
}

revalidateTag and expireTag both update the shared platform tag clock and notify the edge CDN. expireTag also deletes matching Runtime Cache entry objects. If HTTP responses used the same Cache-Tag values, those CDN objects are eligible for purge. See Invalidate and revalidate cached content.

API surface

  • get: returns the stored value, or a miss when missing or expired
  • set: writes a value; optional ttl (seconds), tags, and name
  • delete: removes one key
  • expireTag: removes every entry that carried that tag (or tags)

Maximum item size is 2 MB. Treat the cache as best-effort speed, not durable storage.

Quotas and observability

Workspace plans include a Runtime Cache storage pool. Observability shows usage so you can trim keys or upgrade before writes fail. Prefer namespaced keys per feature so one workload does not crowd out another in the same workspace.