手动失效缓存(续)
- ⚠️ 粒度较粗——失效整个路径下的所有数据
- ✅ 简单场景下够用
三种失效 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 -->|"写后即读<br/>表单提交"| UT["updateTag()"]
Choice -->|"后台刷新<br/>webhook"| RT["revalidateTag(tag, 'max')"]
Choice -->|"简单场景<br/>整页失效"| RP["revalidatePath()"]
style UT fill:#9f9,stroke:#333,stroke-width:2px
style RT fill:#ff9,stroke:#333,stroke-width:2px
style RP fill:#e1f5ff,stroke:#333,stroke-width:2px