{
  "schema_version": "1.0",
  "id": "T-bee2c2ee83f8",
  "url": "https://gpuatlas.top/articles/T-bee2c2ee83f8/",
  "title": "前缀缓存适合什么场景，什么情况下基本没用？",
  "summary": "前缀缓存复用匹配token的输入计算，适合稳定长前缀，动态字段、逐出与独立请求会减少收益。",
  "language": "zh-Hans",
  "category": {
    "id": "c-07",
    "name": "服务性能与成本",
    "url": "https://gpuatlas.top/categories/c-07/"
  },
  "topics": [],
  "body_text": "前缀缓存适合多次请求共享较长且实际匹配的token前缀，比如固定系统说明后追加不同问题，或围绕同一材料连续提问。框架策略、保留与逐出决定是否命中，原文相同只是起点。\n\n它复用已处理前缀状态，主要减少重复输入计算，不是直接返回旧答案。新问题后续生成仍需计算，因此不能将首字改善比例套到完整请求或全部输出。\n\n模板、角色顺序、动态时间戳或前面的字段变化，都可能让共同token变短。先保存实际格式化输入，不能只看文档相同就认为前缀一致，也不应为命中删除必要任务信息。\n\n每次独立内容、共同部分很短、缓存频繁逐出时收益可能小。缓存本身占资源，位于显存、主存或其他层次需按实现核对，不能当作无成本永久知识库或检索替代。\n\n分别测试首次未命中、重复前缀和无关请求，记录输入处理、首字、完整时间与可用命中统计。保存版本、模板及负载顺序，只有在日常比例下质量和响应改善，才说明值得采用，不只报告最好一轮。",
  "published_at": null,
  "modified_at": null,
  "evidence": {
    "type": "documentation_and_conditional_estimates",
    "hardware_tested": false,
    "note": "资料解释与条件估算，非硬件实测。"
  },
  "sources": [
    {
      "id": "llamacpp-server",
      "url": "https://raw.githubusercontent.com/ggml-org/llama.cpp/master/tools/server/README.md",
      "retrieved_at": "2026-11-25T09:52:45.997121+00:00"
    },
    {
      "id": "transformers-kv-cache",
      "url": "https://raw.githubusercontent.com/huggingface/transformers/main/docs/source/en/kv_cache.md",
      "retrieved_at": "2026-11-25T10:07:29.175278+00:00"
    },
    {
      "id": "transformers-chat-template",
      "url": "https://raw.githubusercontent.com/huggingface/transformers/main/docs/source/en/chat_templating.md",
      "retrieved_at": "2026-11-25T10:11:32.915597+00:00"
    }
  ],
  "revision_note": "资料整理与条件估算；非硬件实测。",
  "representations": {
    "html": "https://gpuatlas.top/articles/T-bee2c2ee83f8/",
    "json": "https://gpuatlas.top/data/articles/T-bee2c2ee83f8.json",
    "markdown": "https://gpuatlas.top/data/articles/T-bee2c2ee83f8.md"
  }
}
