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+).string
required
Cache tag to expire and refresh.
refresh
Refresh uncached (dynamic) data on the page (Next.js 16+).noStore
Opt out of caching for the current component/function.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
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:- Fresh: Serve cached entry immediately
- Stale: Serve stale entry, trigger background revalidation
- Expired: Return null (or skip cache)
Cache Deduplication
Multiple concurrent requests for the same cache key are deduplicated:Limitations
Source
View source code → Implementation:/home/daytona/workspace/source/packages/vinext/src/shims/cache.ts