next-cache-components

Enable Next.js cacheComponents and 'use cache' directives for hybrid rendering.

240|75|Updated Dec 3, 2020
One-click install
npx skills add https://github.com/mburumaxwell/paklo --skill next-cache-components-mburumaxwell
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: next-cache-components
Source: https://github.com/mburumaxwell/paklo/tree/main/.agents/skills/next-cache-components
Command: npx skills add https://github.com/mburumaxwell/paklo --skill next-cache-components-mburumaxwell

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Next.js Cache Components address the challenge of delivering fast, responsive UIs by enabling a single route to serve static, cached, and dynamic content. This approach reduces server work and enhances user experience.

Core Features & Use Cases

  • Enable cacheComponents in Next.js to replace experimental PPR and gain a unified caching model.
  • Use the 'use cache' directive at file, component, and function levels to control caching lifetimes (cacheLife), invalidation (cacheTag, updateTag), and data freshness.
  • Common use cases include dashboards, admin panels, and user-specific pages where some content can be cached while others remain dynamic.

Quick Start

Update next.config.ts to enable cacheComponents. Annotate sections of your pages with 'use cache' and configure cacheLife and tags as needed. Monitor cache behavior and adjust revalidation strategies to balance freshness and performance.

Frequently Asked Questions about next-cache-components

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

FAQPage Schema
How do I cache specific components in Next.js without making the entire route static?

You can cache specific components in Next.js by enabling the cacheComponents flag and annotating sections with the 'use cache' directive. This allows a single route to serve static, cached, and dynamic content simultaneously.

What is the 'use cache' directive in Next.js and when should I use it?

The 'use cache' directive in Next.js is an annotation used at the file, component, or function level to control caching behavior. You use it when you need selective caching and explicit invalidation for content like dashboards or admin panels.

How do I manage cache lifetimes and invalidation for Next.js server-rendered pages?

You manage cache lifetimes and invalidation in Next.js by configuring cacheLife for durations and using cacheTag with updateTag for explicit data refresh. This ensures smooth data refresh and controlled cache invalidation across pages.

Does Next.js Cache Components replace experimental Partial Prerendering?

Yes, enabling cacheComponents in Next.js replaces the experimental Partial Prerendering (PPR) feature. It provides a unified caching model that combines static, cached, and dynamic content within a single route to reduce server work.

What's the best way to configure hybrid rendering for user-specific pages in Next.js?

The best way to configure hybrid rendering for user-specific pages is to enable cacheComponents in next.config.ts. You then apply the 'use cache' directive to cache static sections while leaving user-specific content dynamic.

Why does my Next.js route still show stale data after using cache components?

Your Next.js route shows stale data because cache lifetimes need explicit invalidation. You must configure cacheLife for revalidation intervals and use cacheTag with updateTag to forcefully refresh the cached data when underlying changes occur.