What the homework is — keys and values, not memories
When a model reads your prompt, it computes a K and V vector for every token at every layer — the "notes" attention will consult while generating. That work is the expensive part of reading. Press both buttons: the cold request computes notes for all 2,000 prefix tokens; the warm request loads them from storage and only computes the 20 new tokens of your question. The timers and token counters below are the whole story.
Real providers price this explicitly: cached input tokens cost ~10% (sometimes less) of fresh ones. The animation's compute/load split mirrors the real KV-cache reuse; latency ratios are illustrative but directionally faithful.
Prefix or nothing — the cache can't skip around
The rule that surprises everyone: the cache only works on an identical prefix. Token 500's notes depend on tokens 1-499 (that's what attention means), so the moment the streams diverge, everything after the split must be recomputed — even if later parts match exactly. Drag the divergence point and watch the reusable region (gold) get truncated at the first difference, no matter how much matches afterward.
This is causality, not a lazy implementation: token i's KV genuinely encodes everything before it. A "smarter" cache that reused matching middles would return mathematically wrong attention states.
One changed word — hunt the cache-killers
A game of spot-the-expensive-mistake. Below is a prompt template a team ships to production. It looks innocent. Click the parts you think invalidate the cache on every single request. There are three killers hiding in it — find all three and the meter shows your monthly bill dropping by 84%.
The three killers are real patterns from production postmortems: an inline timestamp, a random request-ID "for tracing", and user data interpolated above the static instructions.
Design for the cache — rearrange a real workload
You run a support bot: 10,000 requests/day, each = instructions (2k tokens) + knowledge base (6k) + user message (~200). Three architectures, same content: naive (user message first — "personalization!"), cache-aware (static prefix, user last), and cache-aware + TTL awareness (traffic batched to keep entries warm). The bill is computed live from cache economics; drag the traffic slider to see how volume changes the math.
Pricing model: $3/M fresh input tokens, $0.30/M cached, 5-minute cache TTL refreshed on hit. At low traffic entries expire between hits — watch the middle bar worsen as you drag left.
The agent flywheel — why agents are suddenly affordable
The killer app of caching isn't chat — it's agents. An agent loop appends: each turn is the entire previous conversation plus one new tool result. Without caching, turn N re-pays for all N−1 previous turns — quadratic total cost. With caching, each turn pays mostly for what's new — near-linear. Run a 30-turn agent both ways and watch the two bills separate into different universes.
Each turn appends 600-1,200 tokens (tool results vary). Cumulative curves are integrated live from the same pricing as EP 04. The quadratic-vs-linear gap widens with every turn — try imagining 300 turns.