Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Important
Security Advisory: React2Shell & two new vulnerabilities
Find out more

Custom Next.js Cache Handler

Last updated November 11, 2025

You can configure the Next.js cache location if you want to persist cached pages and data to durable storage, or share the cache across multiple containers or instances of your Next.js application.

Good to know: ThecacheHandler (singular) configuration is specifically used by Next.js for server cache operations such as storing and revalidating ISR and route handler responses. It isnot used by'use cache' directives. For'use cache' directives, usecacheHandlers (plural) instead.

next.config.js
module.exports= {  cacheHandler:require.resolve('./cache-handler.js'),  cacheMaxMemorySize:0,// disable default in-memory caching}

View an example of acustom cache handler and learn more about the implementation.

API Reference

The cache handler can implement the following methods:get,set,revalidateTag, andresetRequestCache.

get()

ParameterTypeDescription
keystringThe key to the cached value.

Returns the cached value ornull if not found.

set()

ParameterTypeDescription
keystringThe key to store the data under.
dataData ornullThe data to be cached.
ctx{ tags: [] }The cache tags provided.

ReturnsPromise<void>.

revalidateTag()

ParameterTypeDescription
tagstring orstring[]The cache tags to revalidate.

ReturnsPromise<void>. Learn more aboutrevalidating data or therevalidateTag() function.

resetRequestCache()

This method resets the temporary in-memory cache for a single request before the next request.

Returnsvoid.

Good to know:

  • revalidatePath is a convenience layer on top of cache tags. CallingrevalidatePath will call yourrevalidateTag function, which you can then choose if you want to tag cache keys based on the path.

Platform Support

Deployment OptionSupported
Node.js serverYes
Docker containerYes
Static exportNo
AdaptersPlatform-specific

Learn how toconfigure ISR when self-hosting Next.js.

Version History

VersionChanges
v14.1.0Renamed tocacheHandler and became stable.
v13.4.0incrementalCacheHandlerPath support forrevalidateTag.
v13.4.0incrementalCacheHandlerPath support for standalone output.
v12.2.0ExperimentalincrementalCacheHandlerPath added.

Was this helpful?

supported.

[8]ページ先頭

©2009-2025 Movatter.jp