Skip to main content
The next/cache module provides APIs for controlling cache behavior, including time-based and tag-based revalidation, ISR, and the new Next.js 15+ "use cache" directive support.

Import

Cache Functions

revalidateTag

Revalidate cached data associated with a specific cache tag.
string
required
Cache tag to revalidate.
string | { expire?: number }
Next.js 16+: cacheLife profile for stale-while-revalidate.

Usage with fetch

Usage with unstable_cache

revalidatePath

Revalidate cached data for a specific path.
string
required
Path to revalidate (e.g., /blog, /products/123).
'page' | 'layout'
Next.js 14+: Revalidate type.
  • 'page' — Revalidate specific page
  • 'layout' — Revalidate layout and all children

Example: Server Action

updateTag

Expire and immediately refresh cached data for a tag (Next.js 16+).
Provides read-your-writes semantics: the cache entry is expired and fresh data is read within the same request, so users immediately see their changes.
string
required
Cache tag to expire and refresh.

refresh

Refresh uncached (dynamic) data on the page (Next.js 16+).
Signals the client to re-fetch dynamic data without touching the cache. Useful for notification counts, live metrics, or status indicators.

noStore

Opt out of caching for the current component/function.
Equivalent to setting Cache-Control: no-store on the response. Also available as unstable_noStore().

unstable_cache

Wrap an async function with caching.

Parameters

(...args: any[]) => Promise<T>
required
Async function to wrap.
string[]
Cache key components. Combined with serialized arguments to form the final key.
object
Cache options.

Example: Cached API Call

”use cache” APIs (Next.js 15+)

cacheLife

Set cache lifetime for a "use cache" function.
string | CacheLifeConfig
required
Built-in profile name or custom config.Built-in profiles:
  • 'default' — 15 min revalidate, ~49 day expire
  • 'seconds' — 30s stale, 1s revalidate, 60s expire
  • 'minutes' — 5 min stale, 1 min revalidate, 1h expire
  • 'hours' — 5 min stale, 1h revalidate, 1 day expire
  • 'days' — 5 min stale, 1 day revalidate, 1 week expire
  • 'weeks' — 5 min stale, 1 week revalidate, 1 month expire
  • 'max' — 5 min stale, 1 month revalidate, 1 year expire
Custom config:

Example: Custom Profile

cacheTag

Tag a "use cache" function for revalidation.
string[]
required
Tags to attach to the cached result.

Cache Handler

Plug in a custom cache backend (Redis, DynamoDB, Cloudflare KV, etc.).

Interface

Usage

Built-in Handlers

MemoryCacheHandler

In-memory cache (default). Not shared across workers/instances.

Cloudflare KV Handler

vinext includes a KV-backed handler for Cloudflare Workers:

CacheHandlerValue Type

ISR (Incremental Static Regeneration)

vinext supports time-based and tag-based ISR:

Time-Based Revalidation

Tag-Based Revalidation

Stale-While-Revalidate

vinext’s ISR layer implements SWR:
  1. Fresh: Serve cached entry immediately
  2. Stale: Serve stale entry, trigger background revalidation
  3. Expired: Return null (or skip cache)

Cache Deduplication

Multiple concurrent requests for the same cache key are deduplicated:

Limitations

Cache key collisions: If two functions use the same keyParts and arguments, they share a cache entry. Use unique keys.
Serialization: Arguments and return values are JSON-serialized. Functions, Symbols, and undefined are not supported.
Server-only: All cache APIs are server-side only. Calling them in client components will throw.

Source

View source code → Implementation: /home/daytona/workspace/source/packages/vinext/src/shims/cache.ts