prompt-caching-strategy
它能做什么
这个工具通过更好地组织你发送给 AI 的指令,帮助你降低成本并加快 AI 的响应速度。它的做法是确保指令中重复的部分始终保持一致,这样 AI 就能复用之前的回答。
适用场景
- ✓当你反复向 AI 发送非常相似的请求时。
- ✓当你希望 AI 响应得更快时。
- ✓当你想降低使用 AI 服务的费用时。
技能链接
https://github.com/affaan-m/ECC/blob/main/skills/prompt-caching-strategy/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我该如何组织我的提示词,让 AI 能用上缓存,从而让我少花钱?”
每周 5 个新技能,1 分钟读完。
工作原理
工具建议把指令中固定不变的部分(比如规则或示例)与每次都会变化的部分(比如当前的问题)分开。这样,AI 就能更容易地识别并复用那些固定部分。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Prompt Caching Strategy
Arrange reusable prompt content to improve cache reuse, then measure input cost and latency. Savings depend on model, platform, cache eligibility, writes, retention, reuse and output volume. Runtime cache hits and savings for this skill are unmeasured; the examples below validate arithmetic without provider calls.
When to Activate
Use for repeated API requests that share authorized instructions, tools or reference material. First identify the exact provider endpoint, model, service tier and caching mode. Consult its current documentation before selecting rates, minimum prefix length or retention. Caching does not reduce context-window use.
How It Works
Preserve a stable prefix
Keep reusable instructions, tool schemas and examples stable; place changing questions, timestamps and retrieved results after that content where the API allows. Respect the provider's serialization order: Claude uses tools, system, then messages. Matching prefixes need identical content, including tool schemas and relevant request settings. A changed prefix can prevent reuse from that point. A dynamic suffix may itself be cached later if reused unchanged.
Reusable prefix: approved tools, instructions, stable examples/reference
Changing suffix: current question, fresh retrieval results, request metadata
Choose only relevant context. Padding prompts or broadening access just to meet an eligibility threshold needs its own cost and quality justification.
Preserve user and workspace boundaries
Authorize content access before cache lookup or reuse. Scope application-managed cache handles and accounting keys to the approved user, workspace, provider account, model and content revision. Share only material explicitly approved for that scope. A cache key is a routing/accounting hint, not an authorization gate or a sandbox. Provider cache isolation does not replace application access checks. Invalidate application references when permissions or content change; follow provider retention/deletion controls. Avoid logging private prompt contents. Context selection, capabilities, sandbox enforcement and evidence remain independent of cache optimization.
Provider Requirements and Usage Evidence
The linked documentation is authoritative; endpoint and SDK versions can expose different usage field names. Record that version alongside counters.
| Provider | Requirements to verify | Counters to record |
|---|---|---|
| OpenAI | Model-specific automatic/explicit modes, minimum length, retention and write/read prices; earlier and newer models differ | Responses usage.input_tokens_details.cached_tokens and, when present, cache_write_tokens; input and output totals. Chat Completions uses prompt_tokens_details.cached_tokens |
| Claude | Supported platform, model minimum, cache_control support and TTL; cache writes may cost more than ordinary input |
input_tokens, cache_creation_input_tokens, cache_read_input_tokens, output_tokens; split writes by TTL when rates differ |
| Gemini | Model minimum and API: Interactions supports implicit caching; explicit cache objects require GenerateContent | Interactions usage.total_cached_tokens; GenerateContent usage_metadata cache/input/output counters plus explicit-cache token count and retained duration |
Use OpenAI's prompt caching guide and pricing for the selected model. For Chat Completions, check the usage schema. Derive ordinary input from the total minus cached reads and any separately reported writes; do not count the same tokens twice.
Use Claude's prompt caching guide
for current model/platform limits and TTL rates. Its input_tokens counts
ordinary input separately from cache reads and writes. A short prefix can produce
zero cache counters even when marked for caching. Do not assume every Claude
model or hosted platform uses the same minimum or read price.
Use Gemini's caching guide, GenerateContent caching guide and pricing. Explicit-cache
…
常见问题
什么是“缓存”?
缓存就像一块临时记忆,用来存放 AI 已经回答过的问题。如果再次遇到相同的问题,它就直接使用存好的答案,而不必从头计算。
这个方法适用于所有 AI 吗?
只适用于部分特定的 AI,比如 OpenAI 和 Claude。每家的设置方法不同,你需要查阅对应的文档。
缓存会减少上下文窗口的大小吗?
不会。缓存并不会减少 AI 对上下文窗口的占用,它只是通过复用信息,让处理过程更快、更省钱。
详情
作者的原始描述
Optimize LLM prompt caching hit rate to reduce API costs and improve latency. Analyzes prompt structure, identifies cacheable vs non-cacheable content, and recommends restructuring to maximize cache reuse. TRIGGER when: user says "prompt cache", "cache hit rate", "reduce LLM cost", "optimize token usage", "cheaper LLM calls", or asks about prompt caching strategies for OpenAI/Anthropic/other provi
repo: affaan-m/ECC
热度
- GitHub 星标
- 280k
- 排名
- #386
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
accessibility
280k帮你的智能体创建人人都能使用的界面。确保网站和应用对残障人士友好,比如失明或行动不便的用户也能顺畅使用。
agent-architecture-audit
280k让你的智能体检查一切是否正常运行。它能找出并修复 AI 系统中的问题,确保系统按预期工作。
agent-eval
280k帮你的智能体比较不同的 AI 编程工具。它能衡量哪个工具在特定任务上更快、更便宜、更可靠。
agent-harness-construction
280k让你的智能体更好地理解如何完成任务。它会优化智能体使用的工具和指令,提高成功的几率。