Skip to content

.tip

· one of the small things

Put use cache on the component, not the route

With Cache Components on, caching belongs to a subtree, not to a page. A cached post body can sit next to a live view counter in the same response, and the build fails if a cached component reads a cookie it shouldn't.

async function Post({ slug }) {
  "use cache";
  cacheTag(`post:${slug}`);
  return <Article post={await getPost(slug)} />;
}

The decision moves to the place that knows what the data depends on, and that's the component.

nextjscaching

Longer version: the post this came from.