Agent skill

Cache Components

by sangrokjung in sangrokjung/claude-forge

Expert guidance for Next.js Cache Components and Partial Prerendering (PPR).

MITAuto-check passedBackend & APIs

Install Cache Components

skills CLI
$ npx skills add sangrokjung/claude-forge --skill cache-components -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install sangrokjung/claude-forge cache-components --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/sangrokjung/claude-forge.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/cache-components .claude/skills/cache-components && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
cache-components
GitHub stars
850
Token cost
~3.7k tokens
SKILL.md length
679 words
Files
4
Skills in repo
24
Repo updated
First seen
Licence
MIT

At a glance

Expert guidance for Next.js Cache Components and Partial Prerendering (PPR).

  • Works in 5 steps: 'use cache' Directive → cacheLife() - Control Cache Duration → cacheTag() - Tag for Invalidation → …
  • Tasks that involve Caching
  • SKILL.md covers Project Detection, Philosophy: Code Over…, Core Concept and Mental Model: The Caching…, plus 9 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Cache Components is an agent skill from sangrokjung/claude-forge. Expert guidance for Next.js Cache Components and Partial Prerendering (PPR). PROACTIVE ACTIVATION: Use this skill automatically when working in Next.js projects that have cacheComponents: true in their next.config.ts/next.config.js. When this config is detected, proactively apply Cache Components patterns and best practices to all React Server Component implementations. DETECTION: At the start of a session in a Next.js project, check for cacheComponents: true in next.config. If enabled, this skill's patterns…

Its SKILL.md is about 3.7k tokens, which your agent loads only when the skill is triggered. The skill folder holds 3 other files (for example `PATTERNS.md`, `REFERENCE.md` and `TROUBLESHOOTING.md`).

It sits in Backend & APIs, covering Caching. It works with Next.js and React. The repository describes itself as: oh-my-zsh for Claude Code — 16 agents, 35 commands, 32 skills, 21 safety hooks in one install. v4.0 adds an adversarial review loop: a second agent that never sees the first… The licence is MIT.

When your agent uses it

  • Tasks that involve Caching

Example prompts

  • “use cache”
  • “/cache-components”

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. 'use cache' Directive
  2. cacheLife() - Control Cache Duration
  3. cacheTag() - Tag for Invalidation
  4. updateTag() - Immediate Invalidation
  5. revalidateTag() - Background Revalidation

What it can do on your machine

Read from SKILL.md and the folder at commit 34d881d. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are typescript and bash).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Cache Components loads about 3.7k tokens when it runs. Until then it costs about 232 tokens; SKILL.md has 679 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~232
When it runs · the whole SKILL.md, loaded when a task matches
~3.7k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from sangrokjung/claude-forge at commit 34d881d, republished under its MIT licence (© sangrokjung). 679 words, ~3,681 tokens.

Download SKILL.mdSave it as .claude/skills/cache-components/SKILL.md (or your agent's skills folder). This skill also uses 3 other files; get the full folder from GitHub.
name
cache-components
description
Expert guidance for Next.js Cache Components and Partial Prerendering (PPR). **PROACTIVE ACTIVATION**: Use this skill automatically when working in Next.js projects that have `cacheComponents: true` in their next.config.ts/next.config.js. When this config is detected, proactively apply Cache Components patterns and best practices to all React Server Component implementations. **DETECTION**: At the start of a session in a Next.js project, check for `cacheComponents: true` in next.config. If enabled, this skill's patterns should guide all component authoring, data fetching, and caching decisions. **USE CASES**: Implementing 'use cache' directive, configuring cache lifetimes with cacheLife(), tagging cached data with cacheTag(), invalidating caches with updateTag()/revalidateTag(), optimizing static vs dynamic content boundaries, debugging cache issues, and reviewing Cache Component implementations.

Next.js Cache Components

Auto-activation: This skill activates automatically in projects with cacheComponents: true in next.config.

Project Detection

When starting work in a Next.js project, check if Cache Components are enabled:

bash
# Check next.config.ts or next.config.js for cacheComponents
grep -r "cacheComponents" next.config.* 2>/dev/null

If cacheComponents: true is found, apply this skill's patterns proactively when:

  • Writing React Server Components
  • Implementing data fetching
  • Creating Server Actions with mutations
  • Optimizing page performance
  • Reviewing existing component code

Cache Components enable Partial Prerendering (PPR) - mixing static HTML shells with dynamic streaming content for optimal performance.

Philosophy: Code Over Configuration

Cache Components represents a shift from segment configuration to compositional code:

Before (Deprecated)After (Cache Components)
export const revalidate = 3600cacheLife('hours') inside 'use cache'
export const dynamic = 'force-static'Use 'use cache' and Suspense boundaries
All-or-nothing static/dynamicGranular: static shell + cached + dynamic

Key Principle: Components co-locate their caching, not just their data. Next.js provides build-time feedback to guide you toward optimal patterns.

Core Concept

┌─────────────────────────────────────────────────────┐
│                   Static Shell                       │
│  (Sent immediately to browser)                       │
│                                                      │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐  │
│  │   Header    │  │  Cached     │  │  Suspense   │  │
│  │  (static)   │  │  Content    │  │  Fallback   │  │
│  └─────────────┘  └─────────────┘  └──────┬──────┘  │
│                                           │         │
│                                    ┌──────▼──────┐  │
│                                    │  Dynamic    │  │
│                                    │  (streams)  │  │
│                                    └─────────────┘  │
└─────────────────────────────────────────────────────┘

Mental Model: The Caching Decision Tree

When writing a React Server Component, ask these questions in order:

┌─────────────────────────────────────────────────────────┐
│ Does this component fetch data or perform I/O?          │
└─────────────────────┬───────────────────────────────────┘
                      │
           ┌──────────▼──────────┐
           │   YES               │ NO → Pure component, no action needed
           └──────────┬──────────┘
                      │
    ┌─────────────────▼─────────────────┐
    │ Does it depend on request context? │
    │ (cookies, headers, searchParams)   │
    └─────────────────┬─────────────────┘
                      │
         ┌────────────┴────────────┐
         │                         │
    ┌────▼────┐              ┌─────▼─────┐
    │   YES   │              │    NO     │
    └────┬────┘              └─────┬─────┘
         │                         │
         │                   ┌─────▼─────────────────┐
         │                   │ Can this be cached?   │
         │                   │ (same for all users?) │
         │                   └─────┬─────────────────┘
         │                         │
         │              ┌──────────┴──────────┐
         │              │                     │
         │         ┌────▼────┐          ┌─────▼─────┐
         │         │   YES   │          │    NO     │
         │         └────┬────┘          └─────┬─────┘
         │              │                     │
         │              ▼                     │
         │         'use cache'                │
         │         + cacheTag()               │
         │         + cacheLife()              │
         │                                    │
         └──────────────┬─────────────────────┘
                        │
                        ▼
              Wrap in <Suspense>
              (dynamic streaming)

Key insight: The 'use cache' directive is for data that's the same across users. User-specific data stays dynamic with Suspense.

Quick Start

Enable Cache Components
typescript
// next.config.ts
import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
  cacheComponents: true,
}

export default nextConfig
Basic Usage
tsx
// Cached component - output included in static shell
async function CachedPosts() {
  'use cache'
  const posts = await db.posts.findMany()
  return <PostList posts={posts} />
}

// Page with static + cached + dynamic content
export default async function BlogPage() {
  return (
    <>
      <Header /> {/* Static */}
      <CachedPosts /> {/* Cached */}
      <Suspense fallback={<Skeleton />}>
        <DynamicComments /> {/* Dynamic - streams */}
      </Suspense>
    </>
  )
}

Core APIs

1. 'use cache' Directive

Marks code as cacheable. Can be applied at three levels:

tsx
// File-level: All exports are cached
'use cache'
export async function getData() {
  /* ... */
}
export async function Component() {
  /* ... */
}

// Component-level
async function UserCard({ id }: { id: string }) {
  'use cache'
  const user = await fetchUser(id)
  return <Card>{user.name}</Card>
}

// Function-level
async function fetchWithCache(url: string) {
  'use cache'
  return fetch(url).then((r) => r.json())
}

Important: All cached functions must be async.

2. cacheLife() - Control Cache Duration
tsx
import { cacheLife } from 'next/cache'

async function Posts() {
  'use cache'
  cacheLife('hours') // Use a predefined profile

  // Or custom configuration:
  cacheLife({
    stale: 60, // 1 min - client cache validity
    revalidate: 3600, // 1 hr - start background refresh
    expire: 86400, // 1 day - absolute expiration
  })

  return await db.posts.findMany()
}

Predefined profiles: 'default', 'seconds', 'minutes', 'hours', 'days', 'weeks', 'max'

3. cacheTag() - Tag for Invalidation
tsx
import { cacheTag } from 'next/cache'

async function BlogPosts() {
  'use cache'
  cacheTag('posts')
  cacheLife('days')

  return await db.posts.findMany()
}

async function UserProfile({ userId }: { userId: string }) {
  'use cache'
  cacheTag('users', `user-${userId}`) // Multiple tags

  return await db.users.findUnique({ where: { id: userId } })
}
4. updateTag() - Immediate Invalidation

For read-your-own-writes semantics:

tsx
'use server'
import { updateTag } from 'next/cache'

export async function createPost(formData: FormData) {
  await db.posts.create({ data: formData })

  updateTag('posts') // Client immediately sees fresh data
}
5. revalidateTag() - Background Revalidation

For stale-while-revalidate pattern:

tsx
'use server'
import { revalidateTag } from 'next/cache'

export async function updatePost(id: string, data: FormData) {
  await db.posts.update({ where: { id }, data })

  revalidateTag('posts', 'max') // Serve stale, refresh in background
}

When to Use Each Pattern

Content TypeAPIBehavior
StaticNo directiveRendered at build time
Cached'use cache'Included in static shell, revalidates
DynamicInside <Suspense>Streams at request time

Parameter Permutations & Subshells

Critical Concept: With Cache Components, Next.js renders ALL permutations of provided parameters to create reusable subshells.

tsx
// app/products/[category]/[slug]/page.tsx
export async function generateStaticParams() {
  return [
    { category: 'jackets', slug: 'classic-bomber' },
    { category: 'jackets', slug: 'essential-windbreaker' },
    { category: 'accessories', slug: 'thermal-fleece-gloves' },
  ]
}

Next.js renders these routes:

/products/jackets/classic-bomber        ← Full params (complete page)
/products/jackets/essential-windbreaker ← Full params (complete page)
/products/accessories/thermal-fleece-gloves ← Full params (complete page)
/products/jackets/[slug]                ← Partial params (category subshell)
/products/accessories/[slug]            ← Partial params (category subshell)
/products/[category]/[slug]             ← No params (fallback shell)

Why this matters: The category subshell (/products/jackets/[slug]) can be reused for ANY jacket product, even ones not in generateStaticParams. Users navigating to an unlisted jacket get the cached category shell immediately, with product details streaming in.

generateStaticParams Requirements

With Cache Components enabled:

  1. Must provide at least one parameter - Empty arrays now cause build errors (prevents silent production failures)
  2. Params prove static safety - Providing params lets Next.js verify no dynamic APIs are called
  3. Partial params create subshells - Each unique permutation generates a reusable shell
tsx
// ❌ ERROR with Cache Components
export function generateStaticParams() {
  return [] // Build error: must provide at least one param
}

// ✅ CORRECT: Provide real params
export async function generateStaticParams() {
  const products = await getPopularProducts()
  return products.map(({ category, slug }) => ({ category, slug }))
}

Cache Key = Arguments

Arguments become part of the cache key:

tsx
// Different userId = different cache entry
async function UserData({ userId }: { userId: string }) {
  'use cache'
  cacheTag(`user-${userId}`)

  return await fetchUser(userId)
}

Build-Time Feedback

Cache Components provides early feedback during development. These build errors guide you toward optimal patterns:

Show full SKILL.md (268 more words)Show less
Error: Dynamic data outside Suspense
Error: Accessing cookies/headers/searchParams outside a Suspense boundary

Solution: Wrap dynamic components in <Suspense>:

tsx
<Suspense fallback={<Skeleton />}>
  <ComponentThatUsesCookies />
</Suspense>
Error: Uncached data outside Suspense
Error: Accessing uncached data outside Suspense

Solution: Either cache the data or wrap in Suspense:

tsx
// Option 1: Cache it
async function ProductData({ id }: { id: string }) {
  'use cache'
  return await db.products.findUnique({ where: { id } })
}

// Option 2: Make it dynamic with Suspense
;<Suspense fallback={<Loading />}>
  <DynamicProductData id={id} />
</Suspense>
Error: Request data inside cache
Error: Cannot access cookies/headers inside 'use cache'

Solution: Extract runtime data outside cache boundary (see "Handling Runtime Data" above).

Additional Resources

Code Generation Guidelines

When generating Cache Component code:

  1. Always use async - All cached functions must be async
  2. Place 'use cache' first - Must be first statement in function body
  3. Call cacheLife() early - Should follow 'use cache' directive
  4. Tag meaningfully - Use semantic tags that match your invalidation needs
  5. Extract runtime data - Move cookies()/headers() outside cached scope
  6. Wrap dynamic content - Use <Suspense> for non-cached async components

Proactive Application (When Cache Components Enabled)

When cacheComponents: true is detected in the project, automatically apply these patterns:

When Writing Data Fetching Components

Ask yourself: "Can this data be cached?" If yes, add 'use cache':

tsx
// Before: Uncached fetch
async function ProductList() {
  const products = await db.products.findMany()
  return <Grid products={products} />
}

// After: With caching
async function ProductList() {
  'use cache'
  cacheTag('products')
  cacheLife('hours')

  const products = await db.products.findMany()
  return <Grid products={products} />
}
When Writing Server Actions

Always invalidate relevant caches after mutations:

tsx
'use server'
import { updateTag } from 'next/cache'

export async function createProduct(data: FormData) {
  await db.products.create({ data })
  updateTag('products') // Don't forget!
}
When Composing Pages

Structure with static shell + cached content + dynamic streaming:

tsx
export default async function Page() {
  return (
    <>
      <StaticHeader /> {/* No cache needed */}
      <CachedContent /> {/* 'use cache' */}
      <Suspense fallback={<Skeleton />}>
        <DynamicUserContent /> {/* Streams at runtime */}
      </Suspense>
    </>
  )
}
When Reviewing Code

Flag these issues in Cache Components projects:

  • Data fetching without 'use cache' where caching would benefit
  • Missing cacheTag() calls (makes invalidation impossible)
  • Missing cacheLife() (relies on defaults which may not be appropriate)
  • Server Actions without updateTag()/revalidateTag() after mutations
  • cookies()/headers() called inside 'use cache' scope
  • Dynamic components without <Suspense> boundaries
  • DEPRECATED: export const revalidate - replace with cacheLife() in 'use cache'
  • DEPRECATED: export const dynamic - replace with Suspense + cache boundaries
  • Empty generateStaticParams() return - must provide at least one param

© sangrokjung, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 3 other files in skills/cache-components of sangrokjung/claude-forge.

  • SKILL.md
  • PATTERNS.md
  • REFERENCE.md
  • TROUBLESHOOTING.md

Open the folder on GitHubat commit 34d881d

Compare with similar skills

Cache Components next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Cache Components compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Cache Components this skillsangrokjung/claude-forge850—~3.7kAutomated safety check: PassMIT
Apollo Clientapollographql/skills117—~1.9kAutomated safety check: PassMIT
Nextjsericrisco/rsc-harness167—~5.1kAutomated safety check: PassMIT
Clerk Setupgrowupanand/ConvoForm101—~3kAutomated safety check: PassMIT
Nextjs Data Fetchinggiuseppe-trisciuoglio/developer-kit355—~2.2kAutomated safety check: NotesMIT
Nextjseinverne/dotfiles121—~5.6kAutomated safety check: NotesMIT

Similar skills

  • Apollo Client

    apollographql/skills

    Guide for building React applications with Apollo Client 4.x.

    117 GitHub stars~1.9k tokensUpdated yesterday
    Backend & APIsAuto-check passed
  • Nextjs

    ericrisco/rsc-harness

    A skill your agent uses when building, reviewing, testing, securing, or optimizing a Next.js App Router app: Server vs Client boundaries, use server actions, route handlers, the v15 vs v16 use cache…

    167 GitHub stars~5.1k tokensUpdated yesterday
    Frontend & DesignAuto-check passed
  • Clerk Setup

    growupanand/ConvoForm

    Set up Clerk authentication in any project with the Clerk CLI and official framework quickstarts.

    101 GitHub stars~3k tokensUpdated 2 days ago
    Backend & APIsAuto-check passed
  • Nextjs Data Fetching

    giuseppe-trisciuoglio/developer-kit

    Provides Next.js App Router data fetching patterns including SWR and React Query integration, parallel data fetching, Incremental Static Regeneration (ISR), revalidation strategies, and error…

    355 GitHub stars~2.2k tokensUpdated 28 days ago
    Backend & APIsAuto-check: notes
  • Nextjs

    einverne/dotfiles

    Guide for implementing Next.js - a React framework for production with server-side rendering, static generation, and modern web features.

    121 GitHub stars~5.6k tokensUpdated 1 mo ago
    Backend & APIsAuto-check: notes
  • Nextjs Expert

    LeoYeAI/openclaw-master-skills

    A skill your agent uses when building Next.js 14/15 applications with the App Router.

    2.2k GitHub stars~4.8k tokensUpdated 2 mo ago
    Backend & APIsAuto-check passed

More from sangrokjung/claude-forge

All 24 skills in this repo
  • Debugging Strategies

    sangrokjung/claude-forge

    Master systematic debugging techniques, profiling tools, and root cause analysis to efficiently track down bugs across any codebase or technology stack.

    850 GitHub starsUsed in 13 repos~3.1k tokens
    Auto-check passed
  • Dependency Upgrade

    sangrokjung/claude-forge

    Manage major dependency version upgrades with compatibility analysis, staged rollout, and comprehensive testing.

    850 GitHub starsUsed in 12 repos~2.3k tokens
    Auto-check passed
  • Skill Factory

    sangrokjung/claude-forge

    Analyze session work and automatically convert reusable patterns into Claude Code skills.

    850 GitHub stars~2.7k tokensUpdated 1 mo ago
    Auto-check passed
  • Cc Dev Agent

    sangrokjung/claude-forge

    A skill your agent uses when starting Claude Code projects, writing CLAUDE.md/spec.md, dispatching subagents, or requesting Agent Teams parallel development.

    850 GitHub stars~771 tokensUpdated 1 mo ago
    Auto-check passed
  • Continuous Learning V2

    sangrokjung/claude-forge

    Instinct-based learning system that observes sessions via hooks, creates atomic instincts with confidence scoring, and evolves them into skills/commands/agents.

    850 GitHub starsUsed in 6 repos~1.8k tokens
    Auto-check passed
  • Harness Diet

    sangrokjung/claude-forge

    Measure and shrink the always-loaded context of a Claude Code harness (CLAUDE.md + rules without paths frontmatter) back under budget — migrate narrative to reference files, convert rules to…

    850 GitHub stars~1.9k tokensUpdated 1 mo ago
    Auto-check passed

Works with

Questions about Cache Components

What does Cache Components do?

Expert guidance for Next.js Cache Components and Partial Prerendering (PPR). Cache Components is an agent skill from sangrokjung/claude-forge.js Cache Components and Partial Prerendering (PPR).

When should I use Cache Components?

Cache Components fits situations like: tasks that involve Caching.

How do I install Cache Components in Claude Code?

Run `npx skills add sangrokjung/claude-forge --skill cache-components -a claude-code`. Or copy the skill folder (skills/cache-components in sangrokjung/claude-forge) into .claude/skills/cache-components in your project. Claude Code loads it when a task matches its description.

How do I install Cache Components in Codex?

Run `npx skills add sangrokjung/claude-forge --skill cache-components -a codex`. Or copy the skill folder (skills/cache-components in sangrokjung/claude-forge) into .agents/skills/cache-components in your project. Codex loads it when a task matches its description.

Can I use Cache Components in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add sangrokjung/claude-forge --skill cache-components -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/cache-components, .gemini/skills/cache-components, .github/skills/cache-components and .opencode/skills/cache-components in your project.

What does Cache Components need to run?

SKILL.md names no scripts, command-line tools or credentials: Cache Components is instructions for the agent only.

Does Cache Components access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Cache Components safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Cache Components use?

Cache Components is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Cache Components use?

About 3.7k tokens (SKILL.md is roughly 15k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Cache Components?

Skills that share tags, products or a category with Cache Components: Apollo Client (apollographql/skills, 117 stars), Nextjs (ericrisco/rsc-harness, 167 stars), Clerk Setup (growupanand/ConvoForm, 101 stars) and Nextjs Data Fetching (giuseppe-trisciuoglio/developer-kit, 355 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Cache Components?

sangrokjung (a GitHub user) maintains it in sangrokjung/claude-forge, which has 850 GitHub stars. The repository holds 24 skills in this directory. The repository was last updated on September 3, 2026.

Source: sangrokjung/claude-forge on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.