next-cache-components
БесплатноЗапускает вложенные скриптыНе проверенNext.js 16 caching model expertise covering the 'use cache' directive, cacheLife() API, cacheTag() for invalidation, cacheComponents configuration, and…
от oimiragieo★ 48 звёзд на GitHubОб этом скилле
Next.js Cache Components
Deep expertise on the Next.js 16 caching model. Covers the 'use cache' directive, cacheLife() profiles, cacheTag() invalidation, cacheComponents configuration, and Partial Prerendering (PPR) integration.
When to Apply
Use this skill when:
- Implementing caching in a Next.js 16+ application
- Migrating from
unstable_cacheorrevalidatepatterns to the new caching API - Configuring component-level caching with
cacheComponents - Setting up cache invalidation with tags
- Integrating Partial Prerendering (PPR) with cached components
- Choosing between static generation, ISR, and dynamic rendering
Core Concepts
The Caching Paradigm Shift (Next.js 15 to 16)
Next.js 16 introduces a fundamentally new caching model:
| Feature | Next.js 14 | Next.js 15 | Next.js 16 |
|---|---|---|---|
| fetch() caching | Cached by default | Not cached by default | Not cached by default |
| Route caching | Automatic | Opt-in | 'use cache' directive |
| Data caching | revalidate option |
revalidate option |
cacheLife() API |
| Invalidation | revalidateTag() |
revalidateTag() |
cacheTag() + revalidateTag() |
| Component caching | Not available | Experimental | cacheComponents: true |
Key Principle
In Next.js 16, caching is explicit and opt-in. Nothing is cached unless you explicitly use the 'use cache' directive.
The 'use cache' Directive
Basic Usage
Add 'use cache' at the top of a file or function to enable caching:
// app/page.tsx -- cache the entire page
'use cache';
export default async function Page() {
const data = await fetch('https://api.example.com/data');
const posts = await data.json();
return (
<main>
{posts.map(post => (
<article key={post.id}>
<h2>{post.title}</h2>
<p>{post.body}</p>
</article>
))}
</main>
);
}
Function-Level Caching
Cache individual async functions instead of entire pages:
// lib/data.ts
import { cacheLife, cacheTag } from 'next/cache';
export async function getUser(id: string) {
'use cache';
cacheLife('hours');
cacheTag(`user-${id}`);
const res = await fetch(`https://api.example.com/users/${id}`);
return res.json();
}
export async function getPosts() {
'use cache';
cacheLife('minutes');
cacheTag('posts');
const res = await fetch('https://api.example.com/posts');
return res.json();
}
Component-Level Caching
With cacheComponents: true in next.config.ts, individual Server Components can be cached:
// next.config.ts
const nextConfig = {
cacheComponents: true,
};
export default nextConfig;
// components/user-profile.tsx
import { cacheLife, cacheTag } from 'next/cache';
export async function UserProfile({ userId }: { userId: string }) {
'use cache';
cacheLife('hours');
cacheTag(`user-profile-${userId}`);
const user = await fetch(`/api/users/${userId}`).then(r => r.json());
return (
<div className="profile-card">
<img src={user.avatar} alt={user.name} />
<h2>{user.name}</h2>
<p>{user.bio}</p>
</div>
);
}
Key benefit: The page can re-render while the cached component serves from cache, avoiding redundant data fetches for unchanged components.
Cache Profiles with cacheLife()
Built-in Profiles
import { cacheLife } from 'next/cache';
// Predefined profiles
cacheLife('seconds'); // stale: 0, revalidate: 1s, expire: 60s
cacheLife('minutes'); // stale: 5min, revalidate: 1min, expire: 1h
cacheLife('hours'); // stale: 5min, revalidate: 1h, expire: 1d
cacheLife('days'); // stale: 5min, revalidate: 1d, expire: 1w
cacheLife('weeks'); // stale: 5min, revalidate: 1w, expire: 30d
cacheLife('max'); // stale: 5min, revalidate: 30d, expire: 365d
Custom Profiles
Define custom cache profiles in next.config.ts:
// next.config.ts
const nextConfig = {
cacheLife: {
'blog-post': {
stale: 300, // 5 minutes -- serve stale while revalidating
revalidate: 3600, // 1 hour -- revalidate in background
expire: 86400, // 1 day -- maximum cache lifetime
},
'user-session': {
stale: 0, // Never serve stale
revalidate: 60, // Revalidate every minute
expire: 300, // Expire after 5 minutes
},
'static-content': {
stale: 3600, // 1 hour stale tolerance
revalidate: 86400, // Revalidate daily
expire: 604800, // Expire after 1 week
},
},
};
Usage:
async function getBlogPost(slug: string) {
'use cache';
cacheLife('blog-post');
cacheTag(`blog-${slug}`);
return fetch(`/api/posts/${slug}`).then(r => r.json());
}
Profile Selection G
Установить next-cache-components в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteEditBashGlobGrepВложенные файлы
FAQ
Что делает скилл next-cache-components?
Next.js 16 caching model expertise covering the 'use cache' directive, cacheLife() API, cacheTag() for invalidation, cacheComponents configuration, and Partial Prerendering (PPR). Use when implementing caching strategies in Next.js 16+ applications, migrating from unstable_cache, or optimizing server component rendering.
Как установить скилл next-cache-components?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл next-cache-components запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic