Prompt caching
For engineers
Ordering prompts so the stable part is cached, cutting cost and latency, and keeping the cache from silently breaking
110 questions across four stages: Understand, Apply, Solve and Judge.
Try 5 questions
Practice items, not counted towards your mastery. No account needed.
Check yourself · 1 of 5
A request starts with the same 5,000 tokens as a cached request, then adds a new question. What happens to the 5,000 shared tokens?
Check yourself · 2 of 5
Which part of a request is best placed first, so it can form part of the cached prefix?
Check yourself · 3 of 5
Where do you find out how many input tokens of a request were served from the cache?
Check yourself · 4 of 5
Which change to a shared system prompt is most likely to destroy cache hits?
Check yourself · 5 of 5
Why are agent loops a good fit for prompt caching?
Topics
- How prompt caching reuses a prefix4 min read · Exact-prefix matching, cache writes versus reads, time-to-live and minimum lengths across Claude, OpenAI and Gemini APIs
- Ordering requests for cache hits4 min read · Tools, system prompt and documents first; timestamps, user input and per-request data last; where cache breakpoints go
- Measuring cache hit rate and savings5 min read · Reading cached-token fields in API usage data, hit rate per route, and the real change in cost and latency
- Changes that silently break the cache4 min read · A timestamp in the system prompt, reordered tools, per-user data in the prefix, short time-to-live and edits to earlier history
- Prompt caching inside agent loops5 min read · Append-only histories, stable tool lists, and why compaction and context edits reset the cached prefix
Start here
- Prompt caching (Claude docs) (opens in a new tab)DocsFree
Breakpoints, cache lifetimes, what invalidates the cache and the usage fields that report reads and writes.
- Prompt caching (OpenAI API docs) (opens in a new tab)DocsFree
How automatic prefix caching works on OpenAI models, the cache key and the cached-token usage field.
- Context caching (Gemini API docs) (opens in a new tab)DocsFree
Implicit and explicit caching on Gemini, with storage-time and token-count details.
Helps to know first
110 questions · last verified 2026-12