KV Cache
A KV cache (key-value cache) is a technique used when a large language model (LLM) generates text. The model keeps the attention "key" and "value" tensors it has already computed for earlier tokens in GPU memory and reuses them for each new token, instead of recomputing the whole context every time.[2] This speeds up generation. The trade-off is memory: the cache grows with the length of each sequence, so it becomes a key factor in LLM serving cost and in how much context a system can handle at once.[1][2] Prompt caching offered by API providers applies the same idea across requests: it saves the key-value state for a repeated prompt prefix and reuses it.[9]
What does KV Cache mean in simple terms?
Think of the KV cache as the notes an AI keeps while reading a long text. Rereading everything from the start before writing each new word would be slow, so the model keeps the key points of what it has already read (the keys and values) and picks up from there. Those notes make the next word faster to produce. The problem is that the longer the text, the more notes pile up, and they can fill the desk, which here is GPU memory.[2] These notes are a metaphor: the cache stores numerical tensors, not a written summary.
How can KV Cache be explained with an analogy?
It is like a long meeting where, instead of rereading the full minutes before every comment, you keep a running list of key points and carry on from there.
Where is KV Cache used?
vLLM, UC Berkeley (US) — Cutting wasted cache memory to under 4%
UC Berkeley researchers introduced PagedAttention, which manages the KV cache in fixed-size blocks, similar to how an operating system pages memory, and released the open-source serving engine vLLM in June 2023.[2] They reported that existing systems wasted 60–80% of KV cache memory through fragmentation and over-reservation, and that PagedAttention brought waste below 4%.[2] The technique was presented at ACM SOSP 2023.[1]
Result: 2–4x higher throughput at the same latency compared with FasterTransformer and Orca (SOSP 2023 paper); cache memory waste reduced from 60–80% to under 4%.[1][2]
DeepSeek (China) — Shrinking the cache with MLA
In its DeepSeek-V2 paper (May 2024), DeepSeek introduced Multi-head Latent Attention (MLA), which compresses the KV cache into a latent vector.[3] A smaller cache lets the same GPUs hold longer contexts and more concurrent requests, which supports lower-cost inference.[3]
Result: 93.3% smaller KV cache and up to 5.76x maximum generation throughput compared with DeepSeek 67B (DeepSeek-V2 paper).[3]
Anthropic, Google, OpenAI (US) — Prompt caching pricing
Major APIs offer prompt caching, which reuses the cached state of a repeated prompt prefix.[4][9] Anthropic charges cache reads at 0.1x the base input price for most models, with lower multipliers on some newer models, while 5-minute cache writes cost 1.25x the base input price.[4] Google announced a 75% token discount for cache hits on Gemini 2.5 models in May 2025.[5] OpenAI launched prompt caching in October 2024 with a 50% discount; its current docs say discounts vary by model, up to 95%.[6][9] Rates change, so check each provider's current pricing page.
Result: Cache-read discounts range from 50% (OpenAI at launch) and 75% (Gemini 2.5 at announcement) to 90% (Anthropic standard rate) or more on some newer models.[4][5][6][9]
SqueezeBits — Measuring KV cache quantization
AI model-optimization company SqueezeBits benchmarked 8-bit KV cache quantization in vLLM and TensorRT-LLM with Llama-3.1-8B on an H100 GPU.[8] FP8 or INT8 storage halves KV cache memory. In TensorRT-LLM this raised throughput, mainly by allowing larger effective batch sizes; in vLLM it did not improve throughput in their tests.[8] MMLU accuracy stayed nearly unchanged at 8 bits.[8]
Result: About 50% less KV cache memory; up to 1.45x throughput in a decode-heavy test on TensorRT-LLM, with no gain on vLLM (v0.6.3).[8]
Try it today
- If you use AI APIs, read your provider's prompt caching page and note the prices for cache writes and cache reads.[4][9]
- Put fixed content, such as system instructions and reference documents, at the start of the prompt, and put the part that changes (the user's question) at the end. This raises the chance of a cache hit.[5][9]
- Check the cached-token count in API usage data to confirm that caching is working.[5][6]
- If you run your own models, use the PagedAttention diagrams on the vLLM blog to understand cache fragmentation.[2]
- Before enabling KV cache quantization, benchmark it on your own engine and workload, because results differ by framework.[8]
Limits and direction
The main limit is memory. The KV cache for each request is large and changes size with sequence length, which limits batch size; long-context services hit GPU memory limits first.[1][2] Compressing the cache through quantization trades memory for possible accuracy loss: the cited SqueezeBits tests found little MMLU impact at 8 bits, while lower precision can degrade accuracy.[8] Prompt caching discounts depend on an identical prefix, so changing the start of a prompt can remove the saving.[4][9]
The direction is cache-centered serving architecture. Moonshot AI's Mooncake, the serving platform for its Kimi chatbot, separates prefill and decoding and pools KV cache using CPU-host memory (DRAM) and SSD storage. In tests with real traces it increased effective request capacity by 59–498% over baseline methods, and it won Best Paper at USENIX FAST '25.[7] Where to keep the cache and how to reuse it are becoming central questions in inference infrastructure, and as context windows grow, KV cache management is likely to matter more.[7][8]
Which sources explain KV Cache?
- arXiv (ACM SOSP 2023) — Kwon et al., Efficient Memory Management for Large Language Model Serving with PagedAttention (2023-09-12) — https://arxiv.org/abs/2309.06180
- vLLM Blog — vLLM: Easy, Fast, and Cheap LLM Serving with PagedAttention (2023-06-20) — https://vllm.ai/blog/2023-06-20-vllm
- arXiv — DeepSeek-AI, DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model (2024-05-07, v5 2024-06-19) — https://arxiv.org/abs/2405.04434
- Anthropic — Prompt caching, Claude Platform Docs (accessed 2026-10-13) — https://platform.claude.com/docs/en/build-with-claude/prompt-caching
- Google Developers Blog — Gemini 2.5 Models now support implicit caching (2025-05-08) — https://developers.googleblog.com/gemini-2-5-models-now-support-implicit-caching/
- OpenAI — Prompt Caching in the API (2024-10-01) — https://openai.com/index/api-prompt-caching/
- USENIX FAST '25 — Qin et al., Mooncake: Trading More Storage for Less Computation — A KVCache-centric Architecture for Serving LLM Chatbot (Best Paper, 2025-02) — https://www.usenix.org/conference/fast25/presentation/qin
- SqueezeBits Tech Blog — [vLLM vs TensorRT-LLM] #8. KV Cache Quantization (2024-11-18) — https://blog.squeezebits.com/vllm-vs-tensorrtllm-8-kv-cache-quantization-35079
- OpenAI — Prompt caching, API docs (accessed 2026-10-13) — https://developers.openai.com/api/docs/guides/prompt-caching
Tell us what you think
Your feedback helps us improve the content.