Glossary · 5 minute read
What Is a KV Cache? The Memory That Makes LLM Generation Fast
A KV cache is the store of attention keys and values a transformer model computes for every token in its context, kept in accelerator memory so each new token reuses them instead of recomputing the sequence. It makes generation fast, but its memory grows with context length and concurrency, making it a constraint on serving throughput and cost.
Language models generate text one token at a time, and each new token depends on everything before it. Naively, that would mean reprocessing the entire context for every token, which would make generation unbearably slow. The key-value cache prevents that: attention representations for every token are stored in memory and reused. The cache makes generation fast and consumes memory that grows with context and concurrency, which makes it a central constraint on serving capacity and cost. This explainer covers what it is and why it matters, drawing on FISTA Solutions' AI enablement practice. The architecture it lives in is described in what is a transformer model and the cross-request extension in what is prompt caching.
What is a KV cache?
In a transformer, each layer's attention mechanism computes, for every token, a key vector and a value vector that later tokens use to decide what to attend to. The KV cache stores these keys and values for all tokens processed so far, per layer and per attention head, in accelerator memory. When the model generates the next token, it computes keys and values only for that token and attends over the cached ones. Inference fundamentals are in what is ai inference.
Why is it necessary?
| Without a KV cache | With a KV cache |
|---|---|
| Each generated token recomputes attention over the full context | Each generated token computes only its own keys and values |
| Cost per token grows with context length squared over a sequence | Cost per token grows roughly linearly with context |
| Long outputs become impractically slow | Long outputs stream at steady speed |
| Memory use is lower | Memory use grows with context and concurrency |
The cache trades memory for speed, and the trade is essential for practical generation.
How large is the cache?
Cache size scales with the number of tokens in context, the number of layers, the number of key-value heads, the dimension of each head, and the numeric precision, multiplied across every concurrent request. For large models and long contexts, per-request cache memory can rival or exceed model weight memory, and it is the reason serving systems cap context and concurrency. Context limits are in what is a context window.
How does the cache limit serving capacity?
A server holds model weights once but a KV cache per active request; available memory after weights determines how many requests can run concurrently at a given context length. Throughput, latency, and cost per request follow from that arithmetic, which is why long-context workloads cost more even at the same token price and why memory-heavy GPUs are prized for serving. Serving economics are in ai inference cost and hardware planning in gpu cost for ai.
What techniques shrink or manage it?
- Paged memory management: allocating cache in blocks to avoid fragmentation and raise concurrency.
- Quantized caches: storing keys and values at lower precision.
- Grouped or multi-query attention: sharing keys and values across heads to cut cache size.
- Eviction and compression: dropping or summarizing less relevant older context.
- Context limits: capping tokens per request in policy.
- Speculative and batched decoding: improving utilization of memory bandwidth.
Precision techniques are in what is quantization in ai.
How does prompt caching build on it?
Prompt caching persists the KV state for a shared prefix, such as a system prompt or tool definitions, across requests, so the provider loads it rather than recomputing it. It is the KV cache extended across requests, and it is why stable prefixes earn discounts and faster first tokens. Mechanics are in what is prompt caching.
What should application teams do about it?
Trim context to what the task needs, structure prompts with stable prefixes first, summarize or truncate long conversation histories, set context limits per feature, and measure latency and throughput at realistic concurrency. Each choice moves memory and cost through the cache. Latency budgeting is in what is latency in ai systems and token economics in llm token cost explained.
How does it relate to reasoning and long outputs?
Reasoning models generate long intermediate sequences, all of which live in the cache during generation, so their memory footprint and cost rise with reasoning length. Budgets on reasoning tokens control both. Reasoning behavior is in what is a reasoning model and the compute principle in what is test-time compute.
What does this look like in practice?
A team self-hosting a model for document analysis finds throughput far below expectations. Profiling shows KV cache memory, not compute, is the limit at their long contexts. Paged cache management, quantized caches, trimming retrieved context, and capping per-request context raise concurrency several-fold without new hardware. Their hosted API workloads benefit similarly from shorter contexts and cached prefixes. Private deployment patterns are in how to build a private llm deployment.
How FISTA Solutions accounts for the KV cache
FISTA Solutions sizes self-hosted serving from cache memory at realistic context and concurrency, applies paging, quantization, and context discipline, structures prompts for prefix caching on hosted APIs, and measures throughput and latency before committing hardware. The AI enablement practice delivers the serving platform, AI agents are designed with context budgets, and forward deployed engineers embed with client platform teams. The record behind the approach is 150+ projects with 99.9% uptime.
To size and tune LLM serving on real constraints, message FISTA on WhatsApp, or read serverless vs dedicated inference for how the cache shapes the hosting decision.
Share-ready article cover
Download the generated social format.
Clear answers
Questions raised by this field note.
Straightforward guidance for evaluating scope, fit, and the next step.
01What is a KV cache in simple terms?
When a model reads your prompt, it computes a compact representation of every token that later tokens attend to. The KV cache keeps those representations in memory so that as the model writes its answer one token at a time, it does not have to reread and recompute everything before it.
02Why does the KV cache matter for cost?
It occupies accelerator memory that scales with context length and the number of simultaneous requests. That memory, not model weights, often caps how many requests a server can handle, which drives serving cost per request and explains why long contexts cost more.
03How is prompt caching related to the KV cache?
Prompt caching persists the KV state computed for a shared prefix, such as a system prompt, across requests, so later requests reuse it. The KV cache is the within-request mechanism; prompt caching extends it across requests.
04How do serving systems reduce KV cache memory?
Through paged memory management that avoids fragmentation, quantizing cached values, attention variants that share keys and values across heads, evicting or compressing older context, and limiting maximum context per request.
05Should application teams care about the KV cache?
Yes, indirectly. Context length choices, prompt structure, and concurrency drive memory and cost through the cache. Trimming context, structuring prompts for caching, and setting sensible limits improve throughput and reduce spend.
Continue exploring
Related capabilities
Start with the hard problem
Need the outcome owned, not merely analyzed?
Tell us where delivery is constrained. Weâll map the fastest credible path from intent to verified production.