Learn about the KV cache
Plain guides to the attention cache behind every long prompt: what it is, where it can be kept, and how to stop recomputing it. Every number is dated and every source is linked.
The life of a KV cache, in four stages.
Every guide here explains one part of this path. Start at any stage, or read them in order.
-
Stage 1
Computed
Prefill builds a key and a value for every prompt token, in every layer.
How the KV cache works -
Stage 2
Kept
Prefix caching holds the blocks in GPU memory for the next request with the same start.
Prefix caching -
Stage 3
Evicted or moved
Memory pressure and restarts drop the blocks, unless they are offloaded to DRAM, NVMe or S3.
Where the cache can go -
Stage 4
Reused
A repeated prefix is read back instead of recomputed, on the same server or another one.
When reloading wins
Read
- What is a KV cache? The keys and values a model keeps for tokens it has read: how it works, the size formula with a worked example, prefix caching, and why it fills GPU memory.
- KV cache offloading, explained GPU, DRAM, NVMe, remote stores and S3: what each tier offers, when reading back beats recomputing, and how vLLM, SGLang and others do it.
- Keep the KV cache across restarts The options for vLLM and SGLang, what survives a restart with each, a measured result and a production checklist.
Use and compare
- KV cache size calculator Bytes per token, per prompt and per fleet for common models and precisions, with the formula shown.
- LMCache alternatives Engine built-ins, Mooncake, Dynamo KVBM, storage vendors and KVStash on the same criteria.
- Benchmarks Every KVStash result with its engine, model, GPU, settings and date.
Six terms that come up everywhere.
Short definitions, each linked to the section that explains it in full.
- KV cache
- The attention keys and values a model has computed for tokens it already read, kept so they are not computed again.
- Prefill
- Running the whole prompt through the model to build its KV cache. For long prompts, most of the wait before the first token.
- Prefix caching
- Keeping the KV cache after a request so a later one that starts with exactly the same tokens can skip that prefill.
- KV cache offloading
- Moving the cache out of GPU memory to DRAM, NVMe, a remote store or object storage, and reading it back when needed.
- Time to first token
- How long a request waits before the first output token. The number prefix reuse improves most.
- Cache identity
- The model, revision, precision and layout a cache belongs to. A cache is only valid for the identity that built it.
Bring one workload. We will measure it with you.
Tell us your engine, model, GPUs and where context repeats or gets lost. We reply with what we would measure, what success looks like, and when KVStash is not worth it.
Or write to rudray@kvstash.com