Prompt caching is prefix matching. Static slots go first (system, persona, schema); dynamic slots go last (retrieval, history, user turn). One drifting byte in the prefix evicts the whole cache.
Think of a library copier that already has a stack of pages photocopied for you. Each call, you hand it your document and it skips reprinting pages it has already done at the start. The moment it sees one new word at the top, it has to start the copier from scratch. So you put the boring, unchanging cover pages first and your fresh notes last. If you sneak today's date into the cover page, the copier throws away the whole prepared stack and reprints every page, every single call. That is the trap of cache aware design: a single drifting byte at the top costs you everything below.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Prompt caching changed context engineering from a quality only optimization into a quality plus cost optimization, and the two are now coupled through the layout of the prompt itself. In 2026 both Anthropic and OpenAI bill cached input tokens at roughly 10 percent of the normal rate, and the contract that triggers a cache hit is the same on both providers: a byte identical prefix.
This question is about internalizing that contract and treating prompt layout as a deployment time decision rather than a per call one. The interviewer wants to see that you understand the prefix matching shape, can name the volatility ranking principle, can identify the cache busting patterns that look harmless in code review, and have a sense of the economic stake at scale.
The prefix matching contract
Both major providers in 2026 implement prompt caching as a prefix hash. The provider stores the key value tensors computed for a previously seen prefix, and on a new call it checks whether the new prompt starts with the same bytes. As long as the bytes match, the cache hit reuses the precomputed tensors and only the suffix needs fresh computation.
The granularity of the match matters. Anthropic exposes explicit cache_control markers, you tag the end of a content block as a cache breakpoint, and up to four breakpoints are supported, with a five minute default TTL and a one hour extended tier. OpenAI's caching is implicit: any prefix of 1024 tokens or more is automatically cached when seen twice or more within the TTL window. The two APIs differ in ceremony but agree on the underlying shape.
The non negotiable property is byte identity. Not semantic identity. Not tokenization identity. Byte identity. If you swap two adjacent few shot examples, the bytes differ from that point forward and the cache misses from that point forward. The hash does not care that the meaning is the same.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- Anthropic's Claude Opus 4.7 and Sonnet 4.5 expose `cache_control` breakpoints on system, tools, and message blocks, with five minute and one hour TTL tiers.
- OpenAI's GPT-5 family auto caches any prompt prefix at or above 1024 tokens; no API ceremony required, and cached input tokens bill at a discounted rate.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you structure a multi tenant prompt so each tenant gets caching benefits without leaking other tenants' data?
Two cache layers. The outer prefix (system, schema, generic few shot) is shared across tenants and caches at the platform level. The tenant specific block (persona, policies, tenant data) sits after that boundary and caches per tenant. Anthropic's explicit breakpoints make this cleaner than implicit prefix caching because you control where the per tenant boundary falls.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Putting a per call value (timestamp, request id, today's date) inside the system prompt and being surprised when cache hit rate sits near zero.
60 second bullets to scan on the way to the call.
What prefix matching means and where the cache boundary sits
Which slots are typically static vs which are typically dynamic
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.