Enabling Cache Components in Next.js – Migrating from Legacy Config and Controlling Dynamic Rendering

Cache Components in Next.js offer a modern way to combine dynamic rendering with fast performance. Once enabled, all pages are treated as dynamic by default, and developers can selectively cache parts of the UI using use cache and Suspense boundaries. This article explains how to enable the feature, migrate from legacy config options like dynamic and revalidate, and use new tools like cacheLife and cacheTag for precise control.

enable cacheconfig migrationcacheLifeSuspense

~3 min read · Updated Oct 25, 2025

Enabling Cache Components


To enable Cache Components, set cacheComponents: true in your next.config.ts file:


import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
  cacheComponents: true,
}

export default nextConfig

Changes to Route Segment Config


  • dynamic = "force-dynamic": No longer needed. All pages are dynamic by default.
  • dynamic = "force-static": Replace with 'use cache'. Runtime APIs like cookies() are no longer allowed inside cached components.
  • revalidate: Replace with cacheLife to define cache duration.
  • fetchCache: Not needed. All fetches inside a cached scope are automatically cached.
  • runtime = 'edge': Not supported. Cache Components require Node.js runtime.

Shifting the Mental Model


Before Cache Components: Pages were static by default, and caching was controlled at the route level.

With Cache Components: Everything is dynamic by default. You decide what to cache using 'use cache' and cacheLife at the file, component, or function level.


Examples


Accessing Runtime APIs


Components using cookies() must be wrapped in <Suspense> to allow pre-rendering of the rest of the page:


// app/user.tsx
import { cookies } from 'next/headers'

export async function User() {
  const session = (await cookies()).get('session')?.value
  return '...'
}

// app/page.tsx
import { Suspense } from 'react'
import { User, AvatarSkeleton } from './user'

export default function Page() {
  return (
    <section>
      <h1>This will be pre-rendered</h1>
      <Suspense fallback={<AvatarSkeleton />}>
        <User />
      </Suspense>
    </section>
  )
}

Passing Dynamic Props


Components only become dynamic when they access the value. You can forward runtime props like searchParams without making the parent dynamic:


// app/page.tsx
import { Table, TableSkeleton } from './table'
import { Suspense } from 'react'

export default function Page({ searchParams }) {
  return (
    <section>
      <h1>This will be pre-rendered</h1>
      <Suspense fallback={<TableSkeleton />}>
        <Table sortPromise={searchParams.then((s) => s.sort)} />
      </Suspense>
    </section>
  )
}

Frequently Asked Questions


Does this replace Partial Prerendering (PPR)?


No. Cache Components implement PPR as a feature. The old experimental flag is gone, but PPR remains active.


What should I cache first?


Cache data that doesn’t rely on runtime APIs and can be reused across requests. Use 'use cache' with cacheLife to define behavior.


How do I update cached content quickly?


Use cacheTag to tag cached data, then trigger updateTag or revalidateTag to refresh it.


Written & researched by Dr. Shahin Siami

Related Articles

Advanced Client-Side Routing and Performance Hooks in Next.js

Next.js provides a rich set of client-side hooks and caching utilities that empower developers to build dynamic, responsive, and secure applications. From reading route parameters to tracking navigation state and reporting performance metrics, this guide walks you through the most important tools available in the App Router.

Continue

Handling Authorization and Caching in Next.js: A Developer’s Guide

Next.js introduces powerful experimental features for access control and smart caching. This guide covers the unauthorized() function for custom 401 handling, unstable_cache for persistent memoization, updateTag for instant cache invalidation, and useLinkStatus for inline navigation feedback. Learn how to use these tools to build secure, performant, and responsive applications.

Continue

redirect and refresh in Next.js — Smart Redirects and Client Refreshing via Server Actions

The redirect function in Next.js allows you to navigate users to a new route, returning either a 307 or 303 HTTP response depending on context. It works in Server Components, Client Components, Route Handlers, and Server Actions. The refresh function is used exclusively within Server Actions to refresh the client router. This article explains how both functions work, with practical examples and key considerations.

Continue

NextRequest and NextResponse in Next.js — Managing Cookies, Headers, Redirects, and Rewrites

Next.js extends the native Web Request and Response APIs with NextRequest and NextResponse, offering powerful tools for managing cookies, headers, redirects, rewrites, and JSON responses. These utilities simplify server-side logic and improve control over routing, personalization, and security. This guide walks through their capabilities with practical examples and best practices.

Continue

headers, ImageResponse, notFound, and permanentRedirect in Next.js — Request Handling, Dynamic Images, Errors, and Redirects

Next.js offers powerful tools for handling HTTP requests and responses in Server Components. The headers function lets you read incoming request headers. ImageResponse allows you to generate dynamic images using JSX and CSS. The notFound function renders a custom 404 page, and permanentRedirect enables permanent redirection to another route. This article explains how to use each feature with practical examples.

Continue

A Complete Guide to Using metadata and generateMetadata in Next.js

In modern versions of Next.js, managing page metadata is more powerful and intuitive than ever. Metadata is automatically injected into the <head> of your pages and plays a vital role in SEO, social sharing, and user experience. This guide explains the two main ways to define metadata: using the static metadata object and the dynamic generateMetadata function.

Continue