Skip to lesson
Exit
LLM Inference Fundamentals for the Routing Engineer1 / 2

2 min lesson

Prefix caching: reuse the work you already did

Compare both sides of "Prefix caching: reuse the work you already did", then name the condition that decides between them.

Step 1 of 2

Prefix caching: reuse the work you already didthe lever with Cursor's name on it

If two requests start with the same tokens, their KV cache for that shared span is identical. Prefix caching keeps those computed keys and values around and reuses them, so a request that shares a prefix skips prefilling it entirely. Prefill then starts at the first token that differs from the cached prefix and runs over everything after it.

Cursor's prompts are unusually repetitive, which is exactly the condition prefix caching loves. The same system prompt, the same tool definitions and often the same file or repo context get sent across many requests in a session. A high prefix-cache hit rate turns an expensive full prefill into a much cheaper cache read. On current provider pricing a cache read bills at a small fraction of the input rate, though the first write of a prefix can cost more than plain input.

COLD MISS vs WARM PREFIX

Interactive diagram. Tab through its regions; each focused region shows its detail in the panel below.

diagram: compare

The same request, two cache outcomes, and why affinity routing decides which one you get.

Learn more

Full explanation

Full explanation

Interview move

Connect prefix caching to routing explicitly: prefix-cache affinity means "send requests that share a prefix to the same instance." Affinity-aware routing, hashing on the prefix or the session, is a lever a routing engineer owns. Then say the cost out loud: pinning prefixes can turn one instance hot, so you balance affinity against load.

Watch out

Prefix caching only helps for an exact token-prefix match from position zero. Change one token early in the prompt, say by reordering the system message, injecting a timestamp or varying the tool list, and the cache misses from that point on. "Keep the stable, shared content at the front and the volatile content at the back" is the correctness rule that makes the cache actually pay off.

QWhy does prefix-cache affinity push you away from naive round-robin load balancing?