A Context Window Is Not Memory: What KV and Prefix Caches Actually Change
Separate context windows, key-value cache, prefix caching, and persistent application memory before choosing an LLM design. The context-path test connects evidence position, token-weighted reuse, cache capacity, concurrency, latency, retention, and accepted output instead of treating a larger advertised window as dependable memory.
A field note by Edgar Domínguez Llanos for IMPAKT.
A context window is addressable working space, not dependable memory. A key-value cache stores attention state for an active sequence; a prefix cache can reuse state for an identical shared prefix. These mechanisms change different constraints. Choose among them by measuring evidence use, repeated-prefix share, cache capacity, concurrency, latency, and retention boundaries on the actual workload. Buying the largest advertised window without that test can increase cost and memory pressure without improving accepted answers.
Separate three mechanisms hidden by one label
The context window is the maximum token span available across the supplied prompt and generated sequence under a stated configuration. Current vLLM model-configuration documentation describes its maximum model length as covering prompt and output, while individual providers or runtimes may impose separate ceilings. The window is the working surface available to the request; effective evidence use remains a separate measured property.
The key-value cache, often shortened to KV cache, retains intermediate attention state for tokens already processed in a sequence. During generation, the system can use that state instead of recomputing the entire prefix at every new token. It is runtime working state, distinct from organizational memory.
A prefix cache reuses previously computed state when later requests share an identical cacheable prefix. It is useful for repeated system instructions, stable document packets, or other genuinely shared prefixes. It supplies reusable state rather than evidence retrieval; variable prompts still produce different paths.
These distinctions matter because each mechanism has a different unit, cost, and control path. “The model remembers” hides all three.
A larger desk can still bury the evidence
The Lost in the Middle study tested how language models used relevant information at different positions in long input contexts. Its reported results show accepted input length and effective evidence use diverging in the studied settings. Keep the finding attached to its models and tasks, then test the position and structure of the evidence your workflow actually supplies.
Effective context can change with the number of relevant items, distractors, document order, prompt structure, language, modality, and required synthesis. A retrieval system may reduce the input while increasing relevance. A structured summary may help one task while removing detail required by another. Additional text can dilute usable evidence.
Define the context test before selecting a limit:
- place decisive evidence at early, middle, and late positions;
- vary the number of relevant and distracting items;
- include conflicting, stale, and missing evidence;
- test the exact synthesis and citation behavior required;
- preserve invalid and severe cases rather than averaging them away.
The result defines one workload's effective-context envelope and its transfer boundary.
KV cache converts context into a capacity decision
Attention state consumes memory as retained tokens and concurrent sequences grow. The PagedAttention paper describes memory management for KV cache and evaluates its serving approach under specified workloads. It supports the mechanism that cache allocation and fragmentation affect serving capacity; its published throughput results stay inside the evaluated runtime and demand distribution.
For an operator, the relevant variables include retained token count, model layers, key-value heads, head dimension, cache precision, concurrent sequences, and runtime allocation. The exact formula depends on architecture and implementation. That makes a long-window purchase partly a capacity-allocation decision.
If longer requests consume more cache, the system may support fewer concurrent sequences or require more memory. A model that accepts the input can still miss a service objective under representative load. Measure memory, queueing, first-token delay, tail latency, and accepted goodput together.
Prefix caching pays only when prefixes really repeat
Prefix caching can remove repeated prefill work for a stable shared prefix. The vLLM automatic prefix caching documentation describes reuse of KV cache blocks for shared prefixes without recomputing those blocks. Measure the benefit for the actual prompt shape and generation path.
Measure repetition as a token-weighted distribution. Ten requests that share a short instruction may create less reusable work than two requests sharing a large, stable dossier. Cache lifetime, eviction, routing, and worker affinity affect whether the state is still available when the next request arrives.
Record these fields:
- exact normalized prefix and version;
- reusable tokens per request and hit rate by service class;
- cache lifetime, eviction, and routing behavior;
- prefill time with and without a hit;
- memory occupied and concurrency displaced;
- invalidation rule after policy, evidence, or prompt change.
A cache hit measures serving reuse. Re-run the task-acceptance rubric when the prefix content or system configuration changes.
Cache storage remains part of the data path
Neither a KV cache nor a prefix cache sits outside governance because it is “temporary.” Cache state can encode information derived from prompts or retrieved evidence. Its location, operator, isolation, lifetime, deletion behavior, logs, snapshots, and failure paths belong in the workload's data and retention map.
The same applies to application memory. If the system stores summaries, user preferences, tool results, or workflow state across sessions, name that persistent store directly. Define who can write it, who can read it, how it expires, how incorrect state is corrected, and what evidence appears in a trace.
Use a context-path test card
For each workload, record four linked tests.
Evidence-use test: cases, evidence positions, distractors, synthesis requirement, citation rule, acceptance threshold, and severe failures.
Sequence-state test: prompt and output distributions, retained tokens, cache precision, memory at representative concurrency, queueing, and recovery after eviction or worker failure.
Reuse test: prefix normalization, token-weighted reuse, hit and eviction rates, saved prefill work, displaced capacity, and invalidation.
Control test: every location and operator for prompts, retrieval, KV state, reusable prefixes, logs, backups, and support access, with retention and deletion evidence.
Compare candidate configurations only after all four pass. One may win for long document analysis while another wins for short, bursty interaction. A routing seam is justified only if the difference exceeds its classification, observability, and recovery burden.
Synthetic worked workload — policy-dossier answer. Workload POL-DOSSIER-01 answers an employee policy question from one approved, versioned dossier and must cite the supporting passage. Move the decisive passage through early, middle, and late positions; vary distractors; and measure accepted answers, unsupported citations, first-token latency in milliseconds, memory in gigabytes, and concurrent requests. Reuse the stable policy header only when its exact version matches, then record hit rate and displaced capacity. Retain cache state under the dossier's access and deletion rules. This test can qualify one context-and-cache configuration for the named dossier. Its evidence boundary excludes other document sets, languages, service classes, and retention paths.
Carry the four tests into the decision-grade benchmark record so context, cache, quality, service, and recovery stay attached to one configuration.
Decision rule
Buy effective evidence use and accepted capacity at the workload envelope, not an advertised context limit. Use KV and prefix caching only when representative memory, latency, reuse, and control evidence supports them.
What this does not prove
This article does not establish that longer context is worse, that caching always saves cost, or that one runtime's mechanism transfers to another configuration. It does not treat cache state as durable user memory. The cited studies and documentation support bounded mechanisms; workload quality, capacity, privacy, retention, and economics still require local measurement.
Editorial process
This article was extracted from the IMPAKT LLM Operating Playbook with AI-assisted structure, drafting, editing, and metadata preparation. It underwent an independent critique and substantive revision loop against IMPAKT's publication rubric; primary sources are linked beside supported claims, and synthesis, recommendations, and evidence boundaries remain explicit.
Sources
- Liu et al., Lost in the Middle, submitted July 6, 2023; accessed August 29, 2026.
- Kwon et al., Efficient Memory Management for Large Language Model Serving with PagedAttention, submitted September 12, 2023; accessed August 29, 2026.
- vLLM, model configuration API, stable documentation; accessed August 29, 2026.
- vLLM, Automatic Prefix Caching details, documentation for version 0.5.3.post1; accessed August 29, 2026.