data-fetching
Next.js 数据获取 - 服务器操作、缓存、重新验证
📖 中文导读:Next.js 数据获取 - 服务器操作、缓存、重新验证 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。
name: data-fetching description: "Next.js data fetching - Server actions, caching, revalidation" sasmp_version: "1.3.0" bonded_agent: nextjs-expert bond_type: PRIMARY_BOND
Data Fetching Skill
Overview
Modern data fetching in Next.js with server actions, caching strategies, and revalidation.
Capabilities
- Server Actions: 'use server' for mutations
- Caching: Automatic request memoization
- Revalidation: Time-based and on-demand
- Streaming: Progressive rendering
- Parallel Fetching: Promise.all patterns
Examples
// Server Action
'use server'
export async function createPost(formData: FormData) {
const title = formData.get('title')
await db.posts.create({ title })
revalidatePath('/posts')
}
// Data fetching with caching
async function getData() {
const res = await fetch('https://api.example.com/data', {
next: { revalidate: 3600 } // Revalidate every hour
})
return res.json()
}
Caching Options
cache: 'force-cache'- Default, cachedcache: 'no-store'- No cachingnext: { revalidate: N }- Revalidate after N seconds