核心价值明确声明不缓存的实时数据与可再验证的静态数据边界。通过路径与标签刷新机制精确触发页面与数据的更新。RSC 页面:noStore 实时段// app/live/page.tsx import { noStore } from 'next/cache' export default async function Page() { noStore() const r = await fetch('https://api.example.com/live', { cache: 'no-store' }).then(r => r.json()) return <pre>{JSON.stringify(r, null, 2)}</pre> } RSC 页面:标签再验证// app/posts/page.tsx export const revalidate = 300 export default async function Posts() { const list = await fetch('https://api.example.com/posts', { next: { revalidate: 300, tags: ['posts'] } }).then(r => r.json()) return <ul>{list.map((p: any) => <li key={p.id}>{p.title}</li>)}</ul> } Route Handler:触发再验证// app/api/admin/revalidate/route.ts import { revalidateTag, revalidatePath } from 'next/cache' export const runtime = 'edge' export async function POST(req: Request) { const body = await req.json() if (body.tag) revalidateTag(String(body.tag)) if (body.path) revalidatePath(String(body.path)) return Response.json({ ok: true }) } 治理建议对用户特定或高频变动数据使用 `noStore()` 与 `cache: 'no-store'`。对目录页与聚合内容采用标签再验证;对特定页面使用路径再验证进行精确控制。结论`next/cache` 提供统一的缓存边界与再验证机制。结合页面与路由的精细化治理,能在性能与新鲜度之间建立稳定的工程化平衡。

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部
2.000325s