Files
myWiki/concepts/cache-invalidation.md

33 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "Cache Invalidation缓存失效"
created: 2026-05-11
updated: 2026-05-11
type: concept
tags: [cache, system-design, debugging]
sources: [[prompt-caching-architecture]]
---
# Cache Invalidation缓存失效
## 定义
Cache Invalidation 指 [[prompt-caching|Prompt Caching]] 中缓存前缀因字节级不匹配而导致整个缓存树失效的现象。由于 [[prefix-matching|前缀匹配]] 的高严格性,任何对前缀的微小更改都会触发"雪崩式"失效。
## 常见触发源
1. **System Prompt 动态变量**:日期、状态摘要、不确定的路径名
2. **工具定义动态调整**:按需加载/移除工具(→ 使用 [[stub-pattern|Stub 模式]] 规避)
3. **System Message 滥用**:频繁更新 System Message 切换状态(→ 使用消息化状态管理)
4. **压缩操作不当**:独立 API 调用使用不同的 System Prompt
## 失效点识别
系统应记录导致失效的"第一现场"——通过日志追踪失效点的字节偏移,快速定位代码逻辑缺陷。
## 相关概念
- [[prefix-matching|前缀匹配]]
- [[prompt-caching|Prompt Caching]]
- [[cache-hit-ratio|缓存命中率]]
- [[system-message-abuse|System Message 滥用]]