cache-components

Automate caching decisions for Next.js Cache Components with build-time guidance.

Updated Sep 6, 2024
One-click install
npx skills add https://github.com/Jaylaelike/pm25-interactive-thaipbs-app --skill cache-components-jaylaelike
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cache-components
Source: https://github.com/Jaylaelike/pm25-interactive-thaipbs-app/tree/main/.claude/skills/cache-components
Command: npx skills add https://github.com/Jaylaelike/pm25-interactive-thaipbs-app --skill cache-components-jaylaelike

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill provides expert guidance for implementing and debugging Next.js Cache Components and Partial Prerendering (PPR). It helps teams automatically apply patterns when cacheComponents is true, co-locating caching with components and enabling granular static/dynamic rendering. It accelerates adoption and ensures best practices.

Core Features & Use Cases

  • Guided adoption: Auto-detects cacheComponents: true and suggests patterns.
  • Patterns & recipes: Offers patterns from PATTERNS.md and troubleshooting references.
  • In-context recommendations: Helps review and improve existing component implementations for PPR.

Quick Start

  • Enable Cache Components: set cacheComponents: true in next.config.ts.
  • Add 'use cache' to data-fetching functions that can be cached and tag with cacheTag(), then set cacheLife() for lifetimes.
  • Wrap dynamic, non-cached content with Suspense and provide a fallback skeleton.

Frequently Asked Questions about cache-components

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

FAQPage Schema
How do I configure Next.js Cache Components with 'use cache' and cacheTag()?

To configure Next.js Cache Components, enable cacheComponents: true in next.config.ts, add 'use cache' to data-fetching functions, tag them with cacheTag(), and set lifetimes using cacheLife(). This co-locates caching with components for granular static and dynamic rendering.

What is Partial Prerendering and when do I need to wrap dynamic content in Suspense?

Partial Prerendering (PPR) enables granular static and dynamic rendering in Next.js. You need to wrap dynamic, non-cached content in Suspense with a fallback skeleton when cacheComponents is true to catch dynamic data outside Suspense at build time.

How do I invalidate cached data in Next.js server actions using revalidateTag()?

To invalidate cached data in Next.js server actions, use updateTag() or revalidateTag() to manage cache invalidations. The Skill automates these best-practice caching decisions across data fetching, server actions, and UI composition.

Does this approach work with existing Next.js server components or only new projects?

It works with existing Next.js server components by providing in-context recommendations to review and improve current implementations for Partial Prerendering, accelerating adoption and ensuring best practices when cacheComponents is true.

Why are my dynamic Next.js routes failing the build when cacheComponents is enabled?

Builds fail because enabling cacheComponents requires dynamic data outside Suspense to be caught. You must wrap dynamic, non-cached content with Suspense and provide a fallback skeleton to enforce API contracts and pass build-time guidance.

What is the best way to determine what to cache and what to keep dynamic in Next.js?

The best way to determine what to cache is using automated best-practice guidance that applies across data fetching, server actions, and UI composition to decide what to cache, how to invalidate, and where to use Suspense.