next-cache-components

Configure Next.js 16+ Cache Components for static, cached, and dynamic rendering.

Updated May 18, 2026
One-click install
npx skills add https://github.com/yogaprasetya22/mmorpg --skill next-cache-components-yogaprasetya22
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: next-cache-components
Source: https://github.com/yogaprasetya22/mmorpg/tree/main/frontend/.agents/skills/next-cache-components
Command: npx skills add https://github.com/yogaprasetya22/mmorpg --skill next-cache-components-yogaprasetya22

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Next.js apps often struggle to balance fast page loads with the need for fresh, request-specific data; this skill helps you use Cache Components to mix static, cached, and dynamic rendering within the same route.

Core Features & Use Cases

  • Enables Cache Components (Next.js 16+): Turns on cacheComponents in next.config.ts so routes can leverage Partial Prerendering.
  • Separates Static, Cached, and Dynamic content: Uses synchronous logic for static output, the use cache directive for cached data, and Suspense streaming for truly dynamic UI.
  • Controls cache lifetime and invalidation: Uses cacheLife() for staleness/revalidation/expiration and cacheTag() plus updateTag()/revalidateTag() for targeted cache invalidation.
  • Handles runtime-data constraints safely: Prevents invalid usage of cookies(), headers(), and searchParams inside use cache, offering the correct refactor pattern or the use cache: private escape hatch.

Quick Start

Enable Cache Components by setting cacheComponents: true in your next.config.ts, then wrap your async cached data function with use cache and optionally add cacheLife() and cacheTag() for predictable staleness and invalidation.

Frequently Asked Questions about next-cache-components

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I combine static and dynamic content in Next.js app router routes?▼

Cache Components in Next.js 16+ combine static generation, cached async data, and dynamic streaming within the same route using the `use cache` directive, `Suspense` boundaries, and synchronous logic for static output.

How do I enable Partial Prerendering for faster repeat requests in Next.js?▼

Partial Prerendering is enabled by setting `cacheComponents: true` in `next.config.ts`, allowing routes to mix cached async data with dynamic UI streaming for faster repeat requests while keeping user-specific content fresh.

What is the best way to invalidate cached data in Next.js Cache Components?▼

Cache invalidation in Next.js Cache Components is handled by assigning `cacheTag()` to cached functions and then using `updateTag()` or `revalidateTag()` for targeted cache invalidation, alongside `cacheLife()` to control staleness and expiration.

Can I use cookies and headers inside the use cache directive in Next.js?▼

Cookies, headers, and searchParams cannot be used inside the `use cache` directive due to runtime-data restrictions, but you can refactor to safe patterns or use the `use cache: private` escape hatch for request-specific dynamic content.

When should I use cacheLife and cacheTag in Next.js cached components?▼

Use `cacheLife()` to define predictable staleness, revalidation, and expiration times for cached functions, and use `cacheTag()` to label cached data so you can perform targeted cache invalidation when underlying data changes.

Does Next.js Cache Components work with React Suspense for dynamic data fetching?▼

Yes, Next.js Cache Components leverages React Suspense boundaries to stream truly dynamic UI alongside static output and cached async data, ensuring user-specific content remains fresh without blocking the initial page render.