Runtime Cache

Runtime Cache

Runtime Cache is available on all plans.

Runtime cache is a regional, ephemeral cache you can use for storing and retrieving data across Vercel Functions, Routing middleware, and build execution within a Vercel region. It lets you cache data close to where your code runs, reduce duplicate work, and control invalidation with TTLs and tags.

Runtime cache may not share the same cache between build time and runtime depending on whether the region where the build executed matches the runtime region.

For caching complete HTTP responses (entire pages, API responses) in Vercel regions, see CDN cache. For caching build artifacts, see Remote cache.

When to use runtime cache

Runtime cache is best when your functions fetch the same data multiple times or perform expensive computations that can be reused, such as in the following scenarios:

Runtime cache is not a good fit for:

How runtime cache works

Runtime cache stores data in a non-durable cache close to where your function executes. Each region where your function runs has its own cache, allowing reads and writes to happen in the same region for low latency. It has the following characteristics:

The cache sits between your function and your data source, reducing the need to repeatedly fetch the same data. See limits and usage for information on item size, tags per item, and maximum tag length.

Using runtime cache

You can cache your Vercel function with any framework by using the functions of the helper method getCache.

Runtime cache with any framework

This example caches data fetched from the API so that it expires after 1 hour and adds a tag to the cache entry so you can invalidate it later from code:

import { getCache } from '@vercel/functions';

export default {
  async fetch(request) {
    const cache = getCache();

// Get a value from cache
    const value = await cache.get('somekey');

if (value) {
      return new Response(JSON.stringify(value));
    }

const res = await fetch('https://api.vercel.app/blog');
    const originValue = await res.json();

// Set a value in cache with TTL and tags
    await cache.set('somekey', originValue, {
      ttl: 3600, // 1 hour in seconds
      tags: ['example-tag'],
    });

return new Response(JSON.stringify(originValue));
  },
};

Next.js 16 and above

With Next.js 16, you can cache data at runtime in two ways:

Using use cache: remote

Use the use cache: remote directive at the file, component, or function level to cache the output of a function or component.

import type { NextConfig } from 'next';

const nextConfig: NextConfig = {
  cacheComponents: true,
};

export default nextConfig;

Then, use the use cache: remote directive in your code. This example caches data so that it expires after 1 hour and adds a tag to the cache entry so you can invalidate it later from code:

import { cacheLife, cacheTag } from 'next/cache';

export default async function Page() {
  const data = await getData();

return (
    <main>
      <h1>Data</h1>
      <pre>{JSON.stringify(data, null, 2)}</pre>
    </main>
  );
}

async function getData() {
  'use cache: remote'
  cacheTag('example-tag')
  cacheLife({ expire: 3600 }) // 1 hour

const response = await fetch('https://api.example.com/data');
  return response.json();
}

Revalidation

You can control how long data stays cached using the following revalidation options:

Time-based revalidation

This example revalidates the cache every hour:

import { cacheLife } from 'next/cache';

export async function GET() {
  const data = await getProducts();
  return Response.json(data);
}

async function getProducts() {
  'use cache: remote'
  cacheLife({ expire: 3600 }) // 1 hour

const response = await fetch('https://api.example.com/products');
  return response.json();
}

Limits and usage

Runtime Cache property Limit
Item size 2 MB
Tags per item 128 tags
Maximum tag length 256 bytes

TTL and tag updates aren't reconciled between deployments. If you need to update cache behavior after a deployment, purge the runtime cache or modify the cache key.