Caching with use cache.
How Cache Components and the use cache directive change data fetching in Next.js 16
By Sample Author
Cache Components make caching explicit. Anything not marked as cached renders at request time.
Marking a function as cached#
async function getPosts() {
"use cache";
return client.fetch(postsQuery);
}Revalidating#
Tags let you revalidate exactly what changed.
Cache what is stable, stream what is not.
- Run the dev server
- Edit a document in the Studio
- Watch the page update
pnpm dev