Skip to main content
Infrastructure

KV Cache

The KV (Key-Value) cache stores the attention keys and values from already-processed tokens so an LLM can generate each new token without recomputing past work — the single largest consumer of GPU memory during LLM inference, and the primary lever for serving throughput.

AIDOLS Research Team · Editorial standards

Full definition

During autoregressive generation, the transformer's self-attention requires the keys and values of every prior token. Caching them turns generation into linear-cost-per-token rather than quadratic. KV-cache size scales with batch size × sequence length × layers × heads × head-dim, often dominating GPU memory for long contexts. PagedAttention (vLLM) and prefix caching are the two highest-impact optimizations.

Why it matters

KV-cache management is the difference between an LLM serving 1 user per GPU and 50. PagedAttention alone can deliver 2–4× throughput; prefix caching cuts cost further when requests share a long prefix (Anthropic, for example, bills cache hits at 10% or less of the base input price).

Example

A SaaS company's RAG endpoint reuses the same 4,000-token system prompt + retrieved-documents prefix across millions of requests. Prefix caching reduces both latency and cost by ~40%.

Next steps

More infrastructure terms

Source & further reading

Primary source: Kwon et al. — "Efficient Memory Management for Large Language Model Serving with PagedAttention" (vLLM) (2023).

Citation policy: this entry is part of the AIDOLS AI Implementation Glossary and may be quoted for research, journalism, and education with attribution to aidolsgroup.com/en/glossary/kv-cache/.