手动失效缓存(续)
| 值 | 说明 |
|---|
| 不传 | 失效该精确路径 |
'page' | 失效匹配该模式的所有页面(用于动态路由) |
'layout' | 失效该路径及其所有子路径 |
三种 API 对比
| API | 使用场景 | 行为 | 可用位置 |
|---|
updateTag(tag) | 用户操作后立刻看到结果 | 立即失效,等待新数据 | Server Action |
revalidateTag(tag, profile) | 后台刷新、webhook | stale-while-revalidate | Server Action + Route Handler |
revalidatePath(path) | 简单场景、整页失效 | 失效整个路径 | Server Action + Route Handler |
graph LR
User[需要失效缓存] --> Choice{选择方式}
Choice -->|"Server Action<br/>用户操作"| UT["updateTag() ⭐ 首选"]
Choice -->|"webhook<br/>后台任务"| RT["revalidateTag(tag, 'max')"]
Choice -->|"简单场景<br/>不想打标签"| RP["revalidatePath()"]
style UT fill:#9f9,stroke:#333,stroke-width:2px