← All topics

Caching in Next 16 (not enabled here)

Next 16 makes caching opt-in with Cache Components and the use cache directive.

  • Enable with cacheComponents: true in next.config.ts. Dynamic work then needs to sit inside Suspense.
  • Mark a component or function with 'use cache', then tune it with cacheLife() and label it with cacheTag().
  • Inside a Server Action use updateTag(tag) for read-your-writes; revalidateTag(tag, profile) for stale-while-revalidate.
  • This app uses simpler tools: segment config (export const revalidate), revalidatePath, and request-level cache().

See it in this app: src/app/(marketing)/page.tsx uses export const revalidate = 60

import { cacheLife, cacheTag } from "next/cache";

async function getPosts() {
  "use cache";
  cacheLife("hours");
  cacheTag("posts");
  return db.posts.findMany();
}