Understanding Prefix Caching in Hybrid LLMs
The whole post on one page: one real agent prompt traced through Qwen3.5-0.8B's chat template, token IDs and chained block names, why reuse is exact, what each kind of layer must keep, and the measured retries.
An agent sends its whole conversation again on every tool call: the system prompt, the tool schemas, every earlier tool result and reply, and then the one new message at the end. Prefix caching is what makes that affordable. The server keeps the keys and values it computed for the previous request and runs only the tokens it has not seen yet.
On a model where every layer is full attention, that works at almost any token. I replayed an agent retry in llama.cpp on Qwen3-0.6B: a 20-turn chat, cut back to 5, 10, 15 or 19 turns, then a different tool result. Every time, it computed only the 514 new tokens.
Then I ran the same retries on Qwen3.5-0.8B, where 18 of the 24 layers are Gated DeltaNet layers that keep one fixed-size state instead of every token's keys and values. With llama.cpp's default settings, the retries recomputed between 5 and 5,600 tokens the server had already processed, depending on how far back the last state it had saved was. Through the raw completion endpoint, where llama.cpp saves states only near the end of each prompt, a retry at token 9,000 of a 12,000-token prompt recomputed all 9,064 tokens: 2.46 s, against 52 ms on the dense model. Cold, the hybrid was the faster of the two, 3.46 s against 5.53 s for all 12,000 tokens.
This is not a llama.cpp quirk. A recurrent state cannot be rewound, and a sliding window has already dropped the tokens a resume point needs, so every serving stack has to decide where to save them and how much memory to spend on it. And these layers are spreading: of the 19 open models I compare in this article, 12 need such a saved resume point, including 9 of the 13 first listed in 2026.
More concretely, this article walks through:
- How prefix caching works for full attention, from scratch: why reusing cached keys and values is exact, and why a cache block's identity has to hash every block before it, as in Narwhal, the open inference server from Athrael's GPU inference course.
- How a fleet of engines finds a cached prefix. In a replay of an agent trace over 4 engines, cache-aware routing reused 79.3% of the prompt tokens, against 50.6% for round-robin.
- Why sliding-window and recurrent layers (Gated DeltaNet, KDA, Mamba-2) can only resume where a window or a state was saved, with a from-scratch DeltaNet recurrence resumed from a snapshot, and what vLLM, SGLang and llama.cpp save for them.
- What one resume point costs in 19 open models, from their config.json files, and measurements on an M4 Pro.
If you already know how prefix caching works for full attention, feel free to jump straight to Section 4 for the layers that break it, or to Section 7 for the architecture comparison.


