cacheComponents
The cacheComponents flag is a feature in Next.js that causes data fetching operations in the App Router to be excluded from pre-renders unless they are explicitly cached. This can be useful for optimizing the performance of dynamic data fetching in Server Components.
It is useful if your application requires fresh data fetching during runtime rather than serving from a pre-rendered cache.
It is expected to be used in conjunction with use cache so that your data fetching happens at runtime by default unless you define specific parts of your application to be cached with use cache at the page, function, or component level.
Usage
To enable the cacheComponents flag, set it to true in your next.config.ts file:
import type { NextConfig } from 'next'
 
const nextConfig: NextConfig = {
  cacheComponents: true,
}
 
export default nextConfigWhen cacheComponents is enabled, you can use the following cache functions and configurations:
- The use cachedirective
- The cacheLifefunction withuse cache
- The cacheTagfunction
Notes
- While cacheComponentscan optimize performance by ensuring fresh data fetching during runtime, it may also introduce additional latency compared to serving pre-rendered content.
Version History
| Version | Change | 
|---|---|
| 16.0.0 | cacheComponentsintroduced. This flag controls theppr,useCache, anddynamicIOflags as a single, unified configuration. | 
Was this helpful?