What you’ll take away
- A prefix cache stores earlier model computation, not a universal answer to later questions.
- An earlier edit can invalidate downstream state even when later token IDs match again.
- Exact tokens, compatible model state and relevant additional inputs all matter.
- Candidate matching length, actual reusable blocks and measured latency are different quantities.
- Branch isolation, permitted sharing and cache residency remain separate checks.
A saved prefix is work already done, not an answer already written
Imagine an assistant that receives the same equipment manual before several different questions. Reading that long opening costs computation each time. A prefix cache can preserve some of the model's work on the shared opening so a later request does not repeat it. What it saves is numerical attention information, called keys and values, from processing those tokens. It does not save a universal answer to every possible question about the manual. The new question and the answer still need their own processing. [1][4]
Now imagine somebody corrects a sentence near the beginning of the manual. The file name stays the same, and most of the words are unchanged. Can the assistant reuse the old cache anyway? This is a question about whether the saved computation still matches the new input. We will follow a small invented sequence to find the boundary. The explanation concerns ordinary causal language-model attention and documented prefix caching, not every architecture that happens to call its stored state a cache. It also assumes that reuse is allowed for the requests involved; a matching prefix is not itself permission to share private material.
Prefix caching reuses previously computed model state for a matching initial token sequence. In a causal transformer, a KV cache holds per-layer attention keys and values; automatic prefix caching can reuse appropriate cached blocks across requests. vLLM describes the resulting saving as skipping computation for the shared prompt prefix. This is distinct from caching a completed response, retrieving a similar document or retaining the model's learned weights. A new suffix still creates new inference work. [1][4]
Consider an application that supplies a fixed manual before changing task-specific questions. Reuse is valid only while the stored state corresponds to the actual computation required by the new request. A corrected sentence, different adapter or changed input representation can break that correspondence even when a human sees nearly the same document. Our scope is ordinary causal-attention KV reuse, with the documented vLLM V1 block design as an implementation example. Recurrent and hybrid architectures have additional state and checkpoint rules. The article develops a correctness checklist through explicit teaching arrays, without claiming that an inference engine or security configuration was tested.
Appending a question and editing an earlier sentence are different operations
In causal attention, a token can use earlier context but cannot look forward to tokens that have not yet arrived. That gives caching its opportunity: adding a new question after an unchanged opening does not rewrite the earlier tokens' attention information merely because future words now exist. Their saved work can remain usable under the same model and compatible settings. The model then processes the added material using the appropriate earlier state. Hugging Face explains this causal boundary in its cache documentation. [1]
Editing the opening is different. A later token may have used the sentence you changed, so its old numerical state can describe the old context even if that later token's own text is identical. Matching words after the edit do not automatically restore the old cache. The conservative boundary is the unchanged prefix before the first relevant difference, subject to the implementation's other requirements. Think of revising the starting assumptions in a calculation: later lines can look familiar while depending on the old assumption. This analogy explains the dependency; it does not say every individual number must change after every edit. [1][3]
For causal self-attention, future appended tokens do not contribute to the already processed positions. Under an unchanged model and compatible execution context, previously computed keys and values can therefore be retained while additional tokens extend the sequence. Hugging Face describes concatenating new KV states with the saved states and keeping caches per layer. The justification is a dependency boundary, not a claim that a cache recognizes the meaning of the text. [1]
Changing an earlier token breaks the argument for reusing downstream states. Later hidden representations can depend on that earlier position, so equality of a later token ID does not establish equality of its context-dependent KV state. A reuse mechanism must identify a valid common prefix, or provide some separate supported correctness mechanism; it cannot simply reconnect at the next matching word. vLLM's chained block identities encode the preceding prefix as well as each block's own tokens [3]. This is a conservative validity rule: it does not assert that every downstream tensor element necessarily differs, only that the old computation is no longer justified by prefix identity alone.
Compare the tokens the model receives
People compare words and paragraphs. A model receives token IDs after its input has been prepared, and those IDs are the useful comparison boundary for this kind of cache. The vLLM design includes the exact tokens of a block in its identity, together with the preceding prefix [3]. Two prompts that ask almost the same thing are not automatically interchangeable. A changed instruction at the beginning can matter even when the rest of the visible message looks familiar.
The same caution applies when an application prepares a conversation. Compare the actual resulting token sequence, not just the user's text box. Your application may insert role markers or other prompt material before the visible question. If that preparation changes, check the result again instead of assuming a character-level match proves a token-level match. This is a proposed verification habit, not a statement about one particular tokenizer's vocabulary. In the examples below, each number is an invented token identifier. No number represents a real word, and the exercise makes no claim that a certain number of letters always creates a certain number of tokens.
Exact prefix matching operates on the prepared input sequence, not semantic similarity. The vLLM block key includes the tuple of block token IDs and a parent hash representing the preceding prefix [3]. Consequently, two blocks with the same local IDs can have different valid identities when their earlier contexts differ. A similarity score, common document title or matching suffix is insufficient evidence for reusing their computed states.
The application should compare the token IDs produced by its actual prompt preparation, including any conversation formatting it supplies. The recommendation follows from the token-level identity requirement; it is not a claim about the segmentation behavior of every tokenizer. A character-prefix test can be useful for detecting obvious edits, but it should not replace the engine's supported token-level matching contract. Our worked arrays are deliberately detached from a real tokenizer. They expose the matching operation without implying that token 41 denotes a particular word or that token boundaries coincide with visible word boundaries. Preserve the tokenizer and prompt-format revision when reproducing the input, and compare the resulting sequence rather than guessing from appearance.
Locate the first difference in a small worked example
Take this invented original token sequence: [11, 12, 13, 14, 15, 16, 17, 18]. A new request that begins with all eight IDs and adds [19, 20] has an eight-token common prefix. A different request, [11, 12, 13, 14, 15, 16, 90, 91], matches the first six tokens. A third, [11, 12, 13, 99, 15, 16, 17, 18], matches only the first three. Although the third request becomes identical again after position four, the uninterrupted matching prefix has already ended.
These are counts of matching input tokens, not a promise about how many tokens the engine will actually reuse. Stored blocks must still be available, compatible and permitted. The example's lesson is narrower: later matching numbers do not erase an earlier changed context. In the corrected-manual story, keep the genuinely unchanged opening as a candidate for reuse and process the changed material through the engine's supported path. Do not quietly attach old downstream states just because the later pages still contain the same sentences. The causal dependency and chained-prefix design explain why that shortcut needs more than visual resemblance. [1][3]
Let the original input be A=[11,12,13,14,15,16,17,18]. Define B=A+[19,20], C=[11,12,13,14,15,16,90,91] and D=[11,12,13,99,15,16,17,18]. Comparing aligned token IDs from the beginning gives longest common prefix lengths LCP(A,B)=8, LCP(A,C)=6 and LCP(A,D)=3. The four matching IDs at the end of D do not extend its common prefix past the mismatch at zero-based index three.
These arithmetic results identify candidate input correspondence, not effective cache-hit lengths. Reuse additionally depends on the model and relevant input identity, supported state representation, sharing policy and resident cache entries. The arrays illustrate why a block identity includes its parent context rather than only the current block's token IDs [3]. They also follow the causal argument for invalidating downstream reuse after an earlier change [1]. No model was run to obtain these numbers; they are direct sequence comparisons. A real implementation may reuse less than the mathematical common prefix because of block boundaries or other execution requirements, so report candidate matching tokens separately from the engine's observed reusable tokens.
Matching text is only one part of matching computation
A cache contains work done by a particular model. If the model's learned settings change, the old numbers cannot be accepted just because the prompt is the same. That follows from what the cache stores: attention states produced by the model's computations [1]. An application also needs to account for relevant additional inputs. The vLLM design lists adapter identities and hashes for image inputs among the extra information used to distinguish cached blocks [3].
Images make the problem easier to picture. Two requests can contain the same placeholder token pattern while supplying different pictures. Matching the placeholders alone would miss the changed visual input. The documented design therefore includes image identity beyond the placeholder IDs [3]. This does not mean every application should build its own cache key or manually hash uploaded files. Use the serving system's supported mechanism and preserve the information it requires. For the manual example, record which model and adapter handled the document, how the prompt was prepared, and whether any non-text input changed. A matching document name is far too little information to establish compatible saved computation.
The numerical KV tensors arise from a specific model computation. Token equality does not justify reuse across changed model weights or incompatible attention configurations; this is an inference from the attention projections and per-layer cache semantics described by Hugging Face [1]. Within vLLM's documented design, relevant extra hash components include LoRA identities and multimodal input hashes [3]. Model identity is a compatibility boundary, not a claim that every engine serializes the complete model version into each individual block key.
For multimodal input, identical placeholder token IDs can correspond to different image embeddings. vLLM's example incorporates the frontend image-processing identity to distinguish those cases [3]. The general lesson is to retain all computation-relevant input identity required by the implementation. A homemade key containing only a prompt string can omit important state. Conversely, copying the documentation's field names into an unrelated cache does not prove correctness. Use the runtime's supported cache lifecycle, identify the model and adapter configuration, and treat changes to input preparation as a reason to verify compatibility. These checks concern whether the saved state belongs to the new computation; they do not independently authorize cross-user sharing.
Six matching tokens can yield one reusable four-token block
Now add a deliberately simple storage rule: our imagined engine reuses only complete blocks of four tokens. The original eight-token sequence has two complete blocks. The request with the final two tokens changed matches the first six tokens, but only the first four form a complete matching block under this rule. The next two matching tokens sit in a block whose later entries differ. The engine can reuse one block and must process the remaining part through its normal path.
The calculation is floor(6 ÷ 4) × 4 = 4 candidate reusable tokens. Here floor means keeping the whole-number part. Four out of eight prompt tokens is 50 percent, but that is not a claim of 50 percent lower latency. This storage illustration follows the full-block caching behavior described in the vLLM V1 design [3]. It is not a statement that every engine, model or software revision always uses blocks of four or has identical reuse granularity. Record the actual supported policy before turning a common-prefix count into a predicted cache hit. The important distinction survives different block sizes: input similarity and reusable storage units are separate quantities.
Assume a hypothetical full-block reuse policy with block size B=4. The original eight-token prompt comprises two complete blocks. For request C, LCP=6, so the complete-block candidate coverage is floor(LCP/B) times B = floor(6/4) times 4 = 4 tokens. The second block cannot be reused on the strength of its first two matching token IDs, because the four-token block as a whole does not match the required prefix computation.
This example is motivated by the vLLM V1 design's addition of completed blocks to its reusable cache [3]. It does not prescribe a universal block size or cover hybrid-model checkpoint extensions, partial-block mechanisms or every architecture-specific cache manager. Even four candidate tokens are not an observed hit if the stored block has been evicted or falls outside the allowed sharing domain. The ratio 4/8=50 percent describes prompt-token coverage in this invented case. It does not model attention cost, scheduling, memory traffic or time to first token. Keep the mathematical prefix length, policy-limited candidate coverage and observed runtime reuse as three distinct measurements.
Continue from the right state, and keep branches separate
Using a cache correctly involves more than finding a matching opening. The model must also know which saved and new positions belong to the current request. Hugging Face explains that a manually managed attention mask must account for both the past cached tokens and the new tokens [1]. A mask is part of the information controlling which positions attention may use. The cache should not be treated as an unrelated file that can be attached to any similarly sized prompt.
Branching adds another practical detail. Suppose two questions start from the same saved manual. Processing the first question may extend its working cache. The second question must still begin from the intended shared opening, not from an accidentally extended first branch. Hugging Face's prefix-cache example makes a separate copy of the prepared cache for each continuation [2]. Other systems can manage shared blocks and branch ownership differently. The requirement is correct separation of the working histories, not a universal instruction to duplicate every tensor. Prefer the engine's documented high-level generation path unless you have a reason and evidence to maintain the lower-level state yourself.
A cache continuation must satisfy the model API's sequence and mask contract. Hugging Face states that the attention mask covers past_kv_length plus new_tokens_length, and its manual-loop example supplies the newly unprocessed token IDs while extending the mask [1]. Position interpretation and cache layout must also remain compatible with the model's supported execution path. This is a conceptual requirement, not a version-independent recipe for a particular positional argument or an untested code snippet.
Branch ownership is equally important. A mutable cache extended by one continuation cannot silently become the initial state of an unrelated continuation. Hugging Face demonstrates prefix reuse with a copied prepared cache for each new prompt [2]; a serving engine may instead manage references to shared blocks and independent request state. Those are implementation choices around the same correctness boundary. A safe engineering check asks whether each branch starts from precisely the intended prefix and whether appending to one branch can affect another's visible state. The article proposes that check without claiming to have exercised a model runtime, verified concurrent execution or established the behavior of every cache class.
Availability and sharing permission are separate checks
A matching prefix does not mean its stored work is still present. Caches have limited space, and the vLLM design describes freeing references and evicting stored blocks as memory is reused [3]. A request that benefited from a cached manual earlier may need fresh processing later. That can be normal cache behavior, not evidence that the manual changed or that the system forgot its learned knowledge. The learned model and a temporary prompt cache are different things.
Sharing introduces a different boundary. Some requests are allowed to reuse a common public prefix; private contexts may require separation. vLLM documents optional cache salts that restrict reuse to requests with the same salt [3]. This is one supported isolation mechanism, not a complete privacy audit or a replacement for authorization and secure storage. Do not infer permission to share a customer's material from the fact that another request contains matching tokens. Decide the sharing scope deliberately, apply the engine's supported controls, and keep sensitive prompt contents out of casual diagnostic logs. Our example uses invented IDs so its arithmetic can be checked without exposing a real conversation.
Cache correctness and cache residency are distinct. The vLLM V1 design tracks block references, allocates available blocks and removes cache entries during eviction [3]. A valid matching key can therefore fail to produce a hit when its corresponding state is no longer available. Likewise, historical reuse does not establish future residency. Operational records should distinguish a mismatch from an unavailable matching entry when the engine exposes that distinction, without inventing diagnostic detail that the system does not provide.
Authorization forms another boundary. vLLM's optional request salt participates in prefix identity and limits reuse to a shared salt domain [3]. This describes a cache-isolation control, not a certification of complete tenant isolation, logging privacy or collision impossibility. Hash algorithms and sharing policy require their own implementation review. An application should use supported controls consistent with its trust boundaries and avoid recording private raw prompts merely to prove that two keys match. Matching computation is a necessary technical condition for valid reuse; permission to reuse that state and the continued availability of its storage are additional conditions. They should not be folded into a single reassuring cache-hit label.
Measure saved prompt work separately from answer generation
Prefix reuse can help most when a substantial opening is processed repeatedly. The vLLM feature guide gives repeated questions about a long document and continuing conversations as examples. It also draws a limit: automatic prefix caching reduces repeated prompt processing, rather than removing the work of generating new answer tokens [4]. If the answer is long, that remaining work can dominate the wait. A hit is useful evidence about reuse, not a complete account of the experience.
Consider an invented timing budget: 800 milliseconds for prompt processing and 1,200 milliseconds for answer generation, or 2,000 milliseconds total. If a hypothetical change saved 600 milliseconds of prompt work and changed nothing else, the total would become 1,400 milliseconds, a 30 percent reduction. This is arithmetic, not a measured result or a prediction for any model. Real scheduling and execution can also change. A useful comparison records actual prompt length, matched tokens, generated length and the timing boundary. Keep first-token delay separate from the time until the whole answer finishes, and do not turn a token-coverage percentage into a latency guarantee.
Automatic prefix caching targets repeated prefill computation. vLLM's feature documentation distinguishes this from decoding new tokens and explains why a workload with little shared prefix or a dominant decoding phase may benefit less [4]. The operational question is therefore not merely whether a cache hit occurred, but which work was avoided and how that affected the measured request boundary. Queueing, scheduling and other execution costs still belong in a real performance analysis.
For a purely hypothetical budget, let prefill take 800 ms and decoding take 1,200 ms. Saving 600 ms from prefill alone gives 200+1,200=1,400 ms instead of 2,000 ms; the fractional reduction is 600/2,000=30 percent. No inference benchmark supports those invented inputs, and no linear relation between token coverage and time is assumed. A real experiment should preserve model/runtime identity, request preparation, generated length and timing definitions, then report the observed results. Record time to first token separately from end-to-end completion and state whether queueing is included. A cache-hit rate, prompt-token reuse fraction and request-latency change answer different questions and should remain separate fields.
Leave the next engineer a reproducible cache boundary
Return to the manual that was corrected near its beginning. First compare the actual prepared inputs and locate the unchanged prefix. Then establish that the saved state belongs to the same compatible model and relevant additional inputs. Let the runtime apply its supported block and branch rules, and confirm that reuse is permitted and the stored state is available. These steps follow from the causal, identity and lifecycle boundaries in the documentation [1][2][3]. A familiar-looking paragraph is not a substitute for those checks.
The handoff can stay small: record the input-preparation version, model and adapter identity, candidate matching length, observed reuse and the timing boundary. Use safe identifiers or appropriate protected records instead of copying private prompts into a public report. Label any unknown field as unknown. If a later edit changes the first difference, repeat the comparison rather than inheriting yesterday's hit count. The result is a cache that can save repeated work while still representing the current request. Its success is measured by correct, compatible reuse and observed benefit, not by the largest percentage printed next to a cache icon.
A reproducible cache handoff identifies the actual token sequence boundary, compatible model and adapter state, relevant multimodal inputs, cache representation and request-branch ownership. It also identifies the allowed sharing domain and distinguishes candidate prefix coverage from resident reusable state. These are a synthesis of the documented causal attention, prefix-copy and chained block-identity mechanisms [1][2][3], not a new universal cache API.
For the worked arrays, retain the three common-prefix lengths, the explicit hypothetical full-block rule and the separate timing arithmetic. For a real deployment, replace those teaching inputs with observed engine data and state the software version. Keep source retrieval dates distinct from runtime versions: documentation can change while an installed engine remains older. The check is complete only when the new request receives state that belongs to its own valid computation. Matching text, historical speed and a cached block's mere existence cannot independently establish that result. This is why changing an early prompt can require downstream work again, while appending a new question to a truly unchanged, compatible prefix can preserve useful computation.
Sources & further reading
Explore the references behind this guide. External pages may change after our review.
- How caching works · Hugging FaceHugging Face · Accessed 6 Nov 2026
- Cache strategies · Hugging FaceHugging Face · Accessed 6 Nov 2026
- Automatic Prefix Caching - vLLMvLLM project · Accessed 6 Nov 2026
- Automatic Prefix Caching - vLLMvLLM project · Accessed 6 Nov 2026
Article updated 6 Nov 2026.
Found something we should revisit?
Good explanations get better with thoughtful feedback.