What is prompt caching?
Prompt caching is reusing precomputed KV cache states for prompts that share the same beginning, cutting prefill computation and time to first token.
It differs from semantic caching in what is stored: semantic caching keeps ready answers to similar questions, while prompt caching reuses the computed intermediate states of requests sharing a prefix, not answers. Reuse depends on an exact prefix match, cache validity and the server implementation.
- Topic
- Inference and performance
- Also known as
- Prompt cache, prefix caching, context caching
How prompt caching works
- A shared prefix in the prompt, such as the system prompt or a frequently used document, is processed once and its KV cache states are kept.
- When a later request contains the same prefix, the server skips prefill for it and computes only the new part.
- Methods such as RadixAttention keep prefixes in a tree to share them across many requests.
- The cache holds GPU memory, so its size and eviction rules are balanced against batching capacity.
In more detail
Prefix stability and block hash sensitivity
Block-based prefix caches (such as vLLM PagedAttention with automatic prefix caching) hash fixed-size token blocks (for example, 16 tokens per block) sequentially from the start of the prompt. Changing even a single character early in the prompt, such as inserting a live timestamp or user ID at the top, invalidates the cache for every token that follows, so static instructions, tool schemas and reference documents are best placed first and dynamic fields last.
Multi-tier KV offloading and disaggregated serving
When long prefixes exceed GPU HBM capacity, modern serving stacks offload KV cache blocks to host CPU DRAM, NVMe SSDs or distributed memory pools (e.g., LMCache or disaggregated prefill-decode clusters). Although reading KV tensors over PCIe or RDMA is slower than GPU HBM, it is still far faster than recomputing prefill for tens of thousands of tokens.
Measuring the gain and which workloads benefit
Prefix caching delivers its largest gains when the prompt has a high ratio of shared prefill tokens to generated decode tokens, such as long-context RAG, multi-turn chat and agentic tool loops and is typically tracked via cache hit rate and TTFT reduction. For very short prompts or single-turn high-output generation, cache lookup and memory-retention overhead can outweigh the saving.
Commonly confused terms
| Term | How it differs |
|---|---|
| KV cache | The KV cache is the per-request memory buffer storing keys and values for all past tokens during autoregressive decoding, whereas prompt caching is the serving-layer mechanism that persists and shares those KV cache blocks across different requests sharing a prefix. |
| Context compression | Context compression (or context compaction/summarisation) manages how much history fits into a request, whereas prompt caching accelerates prefill for whatever static prefix is repeatedly sent at the start of requests. |
Why prompt caching matters for on-premises AI
In in-house assistants, long system prompts, policy texts and fixed examples repeat on every request; prompt caching avoids recomputing them and cuts time to first token and GPU load. If the cache is shared between users, differences in response time can leak information about another user's content. The cache is therefore separated by permission group or tenant; sensitive documents are kept out of shared prefixes.
A hospital's in-house consultation note assistant keeps a long clinical protocol in its system prompt; prompt caching avoids recomputing it on each request and the cache is separated by department.
Common questions
Does prompt caching carry security risk in multi-user in-house systems?
It can. Sharing one cache across permission groups can leak information through timing differences; the cache is separated by permission group.
Does prompt caching store answers too?
No. It stores only computed intermediate states of the prompt; the answer is generated fresh each time. Storing ready answers is semantic caching.
Related terms
- Prefix caching
- Prefill
- Key-value cache
- Semantic caching
- RadixAttention
- Latency
- System prompt
- Time to first token
Sources
- Gim et al., Prompt Cache: Modular Attention Reuse for Low-Latency Inference, 2023
- Zheng et al., SGLang: Efficient Execution of Structured Language Model Programs, 2023
In the glossary: Glossary, M to Q