Why Coding Session Cache Hit Rates Can Reach Over 90%
Cache hit rate in AI coding assistants measures how much of the context sent to the model can skip recomputing attention intermediates, not how smart the model is. This article explains what the metric actually tracks, why multi-turn coding sessions naturally hit rates above 90%, when caches invalidate, how tiered storage keeps caches alive, and how to distinguish usage problems from service problems.
In coding assistants, the cache hit rate measures not “how smart the model is,” but “how much of the context sent to the model in this request doesn’t need to recompute attention intermediates.” In sessions where you keep editing the same code, hit rates above 90% are not unusual: the conversation history and previously generated code reappear verbatim, while the newly added content is often just tens or hundreds of characters. Interpreting this ratio as a diagnostic signal for billing and latency is more useful than treating it as a model quality score.
What the Hit Rate Actually Measures
When a large language model processes an input, the attention layers store keys and values for tokens already seen—this is the well-known KV cache. Once these intermediates are computed, subsequent tokens can read them directly during decoding or continued encoding, without recomputing the same prefix.
The cache hit rate can be roughly expressed as: the number of reusable prefix tokens, divided by the total input tokens of the current request. The numerator is the segment the server can still match and is allowed to reuse; the denominator includes the system prompt, conversation history, code content, and the new instructions in this turn. It describes computational reuse, not semantic similarity. Two pieces of code that “look similar” but differ in their token sequences usually cannot hit the cache; conversely, even if you plan to rewrite the logic later, as long as the prefix is byte-for-byte identical and the cache still exists, that large segment remains reusable.
A high hit rate therefore only means “repeated prefixes were not recomputed.” It does not guarantee correct answers, nor does it mean the context window was compressed. Tokens in the window still have to be “seen” by the model—it’s just that the cost of seeing them drops from full recomputation to a cache read.
Why the Numerator Is Especially Large When Coding
Programmers’ request patterns differ from casual chat users’. When fixing a bug, people usually stay in one session: first paste a file or repository snippet, then ask the model to change something, then follow up with error output. Each new request carries along the earlier system prompt, conversation, and all previously generated code; what’s genuinely new is often just a one-line change description, an error message, or a few lines of diff.
Consider an order-of-magnitude example rather than a fixed benchmark. Suppose a stable prefix has accumulated to tens of thousands of tokens and this turn adds only two hundred. Even if the server reuses only the prefix and recomputes all new tokens, the hit rate lands near 99%. If the session is shorter, whole files are re-pasted each round, or the wording keeps changing, the hit rate will drop noticeably—which is equally normal.
Common sources of “natural repetition” include:
- Fixed system prompts and coding guidelines, which barely change across turns.
- The full text or large chunks of the same file, with only diffs appended at the end.
- Code the assistant generated in the previous turn, sent back verbatim as history in the next turn.
- Tool-returned directory trees, type definitions, and similar outputs that reappear whenever the question hasn’t changed.
So whether “over 90% is normal” first depends on whether your requests form a prefix-stable incremental conversation. If you start a new session every time, shuffle file order randomly, or rephrase the entire history in different words, a lower hit rate does not necessarily indicate a flawed cache implementation.
Why Caches Get Invalidated
The hit rate is the result of two conditions holding simultaneously: the prefix matches, and the cache still exists. If a single token is inserted, deleted, or replaced anywhere in the prefix, everything after that point is typically invalidated, because attention intermediates depend on prior positions and content. This is a mechanism limitation, not a policy oversight.
The other class of invalidation comes from resources, not text. KV caches grow with sequence length and become very large for long contexts; by default they live in accelerator memory (VRAM). That memory must serve multiple concurrent sessions, and when hot data crowds it, older sessions may be evicted or discarded outright. A session idling for a few minutes, a dropped connection, or routing to another instance without that cache all force the next request back to full computation. From the caller’s perspective, the symptom is the same code suddenly “hitting zero,” with latency and input-side costs rising together.
So a single sample showing ninety-something percent only means the prefix and the cache were both intact at that moment. It cannot be extrapolated to all models, all time periods, or all concurrency levels. Higher concurrency, longer contexts, or instance drift can all push the hit rate of the same workflow down.
Tiered Storage Solves “Whether the Cache Is Still There”
A common industry approach is to turn the cache from temporary data that lives only in VRAM into a multi-layered structure that can be swapped in and out—without changing the definition of a hit. Think of it as three tiers by temperature; this is a general architectural pattern, not tied to any specific vendor’s implementation:
- Hot tier: accelerator VRAM. Sessions currently generating or just interacted with stay here, with the shortest read path—ideal for the minutes of continuous typing.
- Warm tier: host memory. Sessions temporarily idle but likely to return within tens of minutes are swapped out of VRAM to free space for other requests. When the user returns, they’re swapped back in; the cost is mainly a memory-to-VRAM transfer, not recomputing the entire prefix.
- Cold tier: persistent storage. Stable, reusable long prefixes can be stored longer, keyed by content—suited to workflows like “stop to research something, then resume editing the same branch hours later.” Whether anything survives across days depends on the provider’s retention policy and capacity; never assume indefinite persistence.
For developers, the practical implication is concrete: stepping away to a meeting or to check documentation doesn’t necessarily force recomputing tens of thousands of tokens next turn. But swap-in has failure windows—a prefix changed by even one character, a cache past its retention time, or a request scheduled to a node that hasn’t loaded that cache. In those cases, what you should observe is a lower hit rate and higher latency, not a model that “suddenly got dumber.”
Compressing the KV cache—reducing stored state along the sequence dimension—is a separate technical route. Its benefit is that the same VRAM holds longer or more sessions, lowering eviction probability; it does not change the requirement that “prefixes must match to be reusable,” and it shouldn’t be read as architecture automatically pushing hit rates to some fixed percentage. Compression ratios, disk persistence, and retention periods all depend on the actual service specification—don’t substitute marketing claims for measurement.
How to Tell a Usage Problem from a Service Problem
Don’t equate “below some percentage” with dishonest billing. The safer approach is to first stabilize your workflow, then observe how the hit rate responds to your actions.
Keep prefixes stable. Put system prompts, guideline files, and shared code at the front of the message, and don’t rephrase them across turns. Inserting “please restate the requirements in a different tone” in the middle of history invalidates everything from that insertion point onward.
Make increments genuinely incremental. Send diffs instead of re-pasting the whole repository each turn; when you must re-paste, keep file order and whitespace identical. Token-level differences—an extra blank line, a different quote style—invalidate everything after them.
Keep sessions resumable. Stick to the same session and the same routing for the same problem. Frequently starting new conversations means actively discarding existing prefixes. After resuming from idle, check whether latency and hit rate degrade together, to distinguish “cache expired” from “prompt was rewritten.”
Run controlled experiments instead of trusting single data points. Send the same prefix twice in a row: the second should show noticeably lower latency and higher hit rate. If the second is still close to full computation, then suspect retention that’s too short, missing cross-tier swapping, or requests not landing on the instance holding the cache. Test at different context lengths to rule out “the prefix is too short, so the percentage looks low.”
On the billing side, the input token price alone isn’t enough. If the service prices cached tokens separately or at a discount, verify that “cached tokens” and “non-cached tokens” are reported separately, and that non-cached tokens roughly equal the newly added content of this turn. When the accounting is unclear, ask the provider for field definitions rather than guessing from percentages.
Evaluate Latency, Cost, and Correctness Separately
A high hit rate typically brings two tangible effects: faster time-to-first-token, since the long prefix needn’t be recomputed; and lower input-side computation, so if billing follows computation, cost should fall in line with the non-cached portion. It does not bring a third effect: the context hasn’t shrunk, and the model remains constrained by the window and attention quality. Piling ever-longer history into one session keeps the hit rate high, but irrelevant code also occupies the window, and answer quality may degrade. When it’s time to start a new session or extract a stable prefix, do so deliberately—don’t drag all history along forever just to keep the percentage up.
Also watch for the reverse misreading. A low hit rate may simply reflect a task with unstable prefixes: cross-repository searches, switching files every turn, or dynamically inserting retrieval results at the front of the prompt. In that case, restructure the prompt first—pin the invariant system constraints at the very front and place the volatile retrieval snippets afterward, so the longest reusable prefix is as long as possible. Only when the prefix is demonstrably unchanged and consecutive short-interval requests still barely hit is it worth checking whether the provider’s cache retention, scheduling, and statistics match its published documentation.
Takeaways for Practice
In multi-turn code editing, history vastly exceeds the new tokens added each turn, so a hit rate above 90% is the arithmetic result of prefix reuse—a common healthy-range signature, not the only acceptable benchmark. Short sessions, frequently rewritten prompts, and cache eviction under high concurrency all pull the number down, and those drops alone don’t mean the model or platform is “deliberately under-hitting.”
What really needs verifying is threefold: whether the prefix is token-level stable, whether the server still holds that cache, and whether the bill separately accounts for hits and misses. Once all three are clear, the cache hit rate becomes an actionable engineering metric—rather than a percentage for comparing model reputations.
