Cache Components in practice
Oct 28, 2026 · Ada
cachingnext.js
With Cache Components enabled, everything is dynamic by default until you opt into caching with the 'use cache' directive. Cached functions and components become part of the prerendered static shell.
Caching a function
import { cacheLife, cacheTag } from "next/cache"
export async function getPosts() {
"use cache"
cacheLife("hours")
cacheTag("posts")
return db.posts.findMany()
}
cacheLife sets how long an entry stays fresh, and cacheTag gives it a name you can invalidate later with updateTag or revalidateTag.
Request data needs Suspense
Anything that reads request data, such as cookies, headers or searchParams, must sit inside a <Suspense> boundary so the rest of the page can still be prerendered.