next-cache-components

Apply Next.js 16 Cache Components to mix static and dynamic content.

Updated Aug 8, 2024
One-click install
npx skills add https://github.com/CAPJackie/x --skill next-cache-components-capjackie
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: next-cache-components
Source: https://github.com/CAPJackie/x/tree/main/.agents/skills/next-cache-components
Command: npx skills add https://github.com/CAPJackie/x --skill next-cache-components-capjackie

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Next.js developers often struggle to mix static, cached, and request-specific data in the same route while keeping performance high and behavior predictable.

Core Features & Use Cases

  • Enables Cache Components (PPR): Turns on Next.js 16+ Cache Components to replace the older experimental.ppr approach.
  • Provides cache control with directives: Uses the use cache directive at the page, component, or function level to mark eligible code for caching.
  • Supports cache lifetime and invalidation: Sets cache behavior with cacheLife and controls freshness with cacheTag and updateTag, including guidance for when to use revalidate-style background updates.

Quick Start

Configure Next.js by setting cacheComponents: true in next.config.ts, then mark your cached async functions with "use cache" and optionally set cacheLife and cacheTag for revalidation strategy.

Frequently Asked Questions about next-cache-components

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

FAQPage Schema
How do I mix static and dynamic content in a single Next.js route using Cache Components?

Next.js Cache Components let you mix static, cached, and dynamic content in one route by enabling cacheComponents in next.config.ts and using the use cache directive with Suspense-wrapped dynamic segments.

How do I control cache lifetime and invalidation for Next.js App Router data fetching?

Control cache invalidation in Next.js by applying the use cache directive to async functions, then use cacheLife to set cache duration and cacheTag with updateTag for tag-based revalidation.

What are the limitations when using the use cache directive in Next.js?

The use cache directive restricts access to request-specific data; you must avoid calling cookies, headers, or searchParams inside cached functions to prevent runtime errors and maintain predictable static behavior.

Does Next.js 16 Cache Components replace the older experimental PPR setup?

Yes, Next.js 16 Cache Components replaces the older experimental.ppr approach, providing a unified mechanism for partial prerendering by toggling cacheComponents in next.config.ts instead of using experimental flags.

How do I enable partial prerendering for cached database calls in Next.js?

Enable partial prerendering by setting cacheComponents to true in next.config.ts, then mark your cached database calls with the use cache directive to allow static shell generation while streaming dynamic content.

When should I use cacheTag and updateTag instead of background revalidation in Next.js?

Use cacheTag and updateTag for immediate tag-based cache invalidation when underlying data changes, whereas background revalidation is better suited for periodically refreshing cached content regardless of data mutations.