Caching a CMS-Backed Blog with use cache in Next.js 16

The plan said fetch revalidate. The new project template had other ideas.

A surprise in the template

The plan for this blog used fetch(url, { next: { revalidate: 300 } }). But a fresh Next.js 16 project turns on Cache Components by default, and the caching model is different.

What the code looks like now

export async function listPosts(page = 1) {
  "use cache";
  cacheTag("posts");
  cacheLife({ revalidate: 300 });
  // fetch from the CMS
}

Each data function is cached for five minutes and tagged posts.

Refreshing on demand

A small route handler calls revalidateTag("posts", "max") when it receives the right secret. Note the second argument: the single-argument form is deprecated.

One rough edge

Pages read params inside Suspense, so a missing post shows the not-found screen but the response status is 200. It is marked noindex, which is good enough for this example.

← 글 목록