cache-components

Cache data in Next.js server components using the 'use cache' directive.

146|12|Updated Jan 30, 2025
One-click install
npx skills add https://github.com/zoonk/zoonk --skill cache-components-zoonk
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cache-components
Source: https://github.com/zoonk/zoonk/tree/main/.agents/skills/cache-components
Command: npx skills add https://github.com/zoonk/zoonk --skill cache-components-zoonk

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Cache Components lets you co-locate data fetching, caching and rendering decisions inside React Server Components to deliver fast static shells with streaming content, reducing perceived load times and SSR costs.

Core Features & Use Cases

  • Cache data with the 'use cache' directive on server components for granular, cross-user performance gains.
  • Use cacheLife, cacheTag, updateTag, revalidateTag, and revalidatePath for precise invalidation and background updates.
  • Compose pages with static shells plus dynamic Suspense-driven content for optimal balance of speed and freshness.
  • Follow patterns for subshells, hierarchical caching, and multi-tenant scenarios to improve reuse and scalability.

Quick Start

Enable Cache Components in your Next.js project by turning on cacheComponents: true in next.config and begin annotating server components with 'use cache' to enable partial prerendering.

Frequently Asked Questions about cache-components

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

FAQPage Schema
How do I use cache components in Next.js for partial prerendering?

To use cache components in Next.js, enable cacheComponents: true in next.config and annotate server components with 'use cache'. This creates a static shell with streaming content using Suspense for partial prerendering.

What is the 'use cache' directive in React Server Components?

The 'use cache' directive co-locates data fetching and caching inside React Server Components to deliver fast static shells. It requires functions to be async with serializable arguments and return values for granular performance gains.

How do I invalidate cached server components using cacheTag and revalidateTag?

Invalidate cached server components by assigning a cacheTag to cached functions and calling revalidateTag or updateTag to trigger background updates. This ensures precise invalidation and content freshness across routes.

Does the 'use cache' directive work with multi-tenant Next.js applications?

Yes, cache components support multi-tenant Next.js scenarios through subshells and hierarchical caching patterns. You can compose pages with static shells and dynamic Suspense boundaries to improve reuse and scalability across tenants.

Why must cached functions be async when using cache components?

Cached functions must be async because the 'use cache' directive must be the first statement executed. This ensures serializable arguments and return values are properly coordinated with cacheLife and cacheTag for streaming and invalidation.