next-cache-components

Implement Next.js Cache Components for mixed static and dynamic rendering.

885|108|Updated Apr 30, 2025
One-click install
npx skills add https://github.com/legions-developer/invoicely --skill next-cache-components-legions-developer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: next-cache-components
Source: https://github.com/legions-developer/invoicely/tree/main/.agents/skills/next-cache-components
Command: npx skills add https://github.com/legions-developer/invoicely --skill next-cache-components-legions-developer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Next.js routes often need to balance fast page loads with fresh, request-time data, and the cache/partial prerendering behavior can be confusing without clear guidance.

Core Features & Use Cases

  • Enable Cache Components for PPR: Turn on cacheComponents: true to mix static, cached, and dynamic content within a single route.
  • Use cached rendering with directives: Apply use cache at file, component, or function scope and control staleness via cacheLife().
  • Manage cache invalidation: Tag cached data with cacheTag() and refresh it using updateTag() (immediate) or revalidateTag() (background).
  • Handle runtime constraints safely: Avoid cookies(), headers(), or searchParams inside use cache, or use use cache: private when required for compliance.

Quick Start

Update your Next.js configuration to enable cache components, then add use cache plus cacheLife("hours") to the data-fetching server function you want cached while streaming request-specific parts via Suspense.

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 prerendering and dynamic streaming in a single Next.js route?

To mix static prerendering and dynamic streaming in Next.js, enable `cacheComponents: true` in your configuration and apply the `use cache` directive to specific components or functions to selectively cache async data while streaming request-specific parts via Suspense.

How do I invalidate cached data in Next.js Cache Components?

You invalidate cached data in Next.js Cache Components by tagging it with `cacheTag()` during the fetch, then triggering a refresh using `updateTag()` for an immediate refresh or `revalidateTag()` for a background update.

Can I use cookies or headers inside a Next.js use cache directive?

You cannot use `cookies()`, `headers()`, or `searchParams` inside a standard `use cache` directive due to runtime constraints; you must use `use cache: private` instead to handle request-specific data safely.

What is the best way to control cache staleness for Next.js server components?

The best way to control cache staleness for Next.js server components is to apply the `use cache` directive at the function or component scope and define the duration using the `cacheLife()` function, such as `cacheLife("hours")`.

When should I enable cacheComponents in next.config for partial prerendering?

You should enable `cacheComponents` in next.config when your production routes need partial prerendering, selective caching for async data, and tag-based invalidation for frequently changing records within a single route.