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.

  1. Stage 1

    Computed

    Prefill builds a key and a value for every prompt token, in every layer.

    How the KV cache works
  2. Stage 2

    Kept

    Prefix caching holds the blocks in GPU memory for the next request with the same start.

    Prefix caching
  3. 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
  4. Stage 4

    Reused

    A repeated prefix is read back instead of recomputed, on the same server or another one.

    When reloading wins

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