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'use cache'. Runtime APIs like cookies() are no longer allowed inside cached components.cacheLife to define cache duration.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.
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>
)
}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>
)
}No. Cache Components implement PPR as a feature. The old experimental flag is gone, but PPR remains active.
Cache data that doesn’t rely on runtime APIs and can be reused across requests. Use 'use cache' with cacheLife to define behavior.
Use cacheTag to tag cached data, then trigger updateTag or revalidateTag to refresh it.