Files
myWiki/concepts/distributed-prompt-caching.md
2026-06-01 10:46:01 +08:00

45 lines
1.8 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: "Distributed Prompt Caching (分布式提示词缓存)"
created: 2026-05-29
updated: 2026-05-29
type: concept
tags: ["distributed-systems", "prompt-caching", "LLM", "agent"]
sources: ["https://mp.weixin.qq.com/s/MUWV7eug14bktUMlqsxfQw"]
---
# Distributed Prompt Caching (分布式提示词缓存)
**Distributed Prompt Caching** 是将单机 [[prompt-caching]] 机制扩展到多机分布式集群的技术体系,解决跨物理节点的上下文缓存同步问题。在量化交易、多 Agent 协作等分布式场景中至关重要。
## 核心挑战
- **[[cache-cold-start|缓存冷启动]]**:新节点缺少已有会话的前缀哈希,导致全额 Token 重传和秒级重算
- **跨服务商缓存割裂**:不同 LLM 供应商的缓存实现机制完全不同Session ID vs Trie 树匹配)
- **一致性风险**:多节点并发更新同一上下文时可能发生缓存"分叉"
## 解决架构
分布式 Prompt Caching 依赖三个核心组件:
1. **[[global-context-hash-tree]]** — 基于 SHA-256 的会话唯一标识
2. **[[distributed-cache-routing]]** — Redis 骨干网状态路由表
3. **[[active-cache-warmup]]** — 预测性跨机预热
## 与单机 Prompt Caching 的对比
| 维度 | 单机 | 分布式 |
|------|------|--------|
| 缓存范围 | 单实例进程内 | 跨物理节点 + 跨服务商 |
| 标识机制 | 前缀字节匹配 | SHA-256 复合键 |
| 预热方式 | 被动(首次请求即缓存) | 主动Shadow Calling |
| 一致性 | 无需处理 | 乐观锁 + 版本号 |
## 核心原则
> 用**空间的确定性**(高带宽内网 + Redis 路由)换取**时间的确定性**(消除秒级重算延迟)
## 相关
- [[distributed-agent-cache-sync-2026]] — 原始文章
- [[prompt-caching]] — 单机 Prompt Caching
- [[active-cache-warmup]] — 跨机预热机制