Why LLM Cache Hit Rates Reach 96% or Higher

    This article explains why a 96%–99% cache hit rate is normal for long-prefix, multi-turn, and coding workloads. It covers how prefix-based caching works, why token-weighted metrics run high, when a high hit rate signals a problem, how to verify it with an A/B test, and engineering practices that keep it stable.

    1. The Short Answer: 96%–99% Is Usually Normal

    In scenarios like AI coding assistants, long-document question answering, and multi-turn conversations, a 96%–99% cache hit rate is usually neither a measurement error nor a platform billing mistake. It is a direct result of how requests are structured. Whether the number is normal depends on two things: whether your requests share a highly repetitive prefix, and whether the metric is weighted by tokens or by request count.

    Since the second half of 2024, a cloud provider introduced context caching and priced the cached portion extremely low. Other platforms followed with prompt caching or automatic caching for general-purpose LLMs, typically discounting cached tokens by 50% to 90%. By around 2025, “discounts for cache hits” had become an industry norm in model service pricing. The hit rate is therefore no longer just a performance metric; it is a cost metric that shows up directly on the bill.

    2. How Cache Hits Work: Prefix Matching, Not Semantic Similarity

    Mainstream implementations rely on automatic prefix caching in the inference engine. The token sequence of a request is split into fixed-size blocks, each block’s content is identified by a hash, and the corresponding intermediate state (such as attention key-values) is kept in GPU memory or high-speed storage. When a new request arrives, blocks are compared hash by hash from the first one until the first mismatch. Everything before that point counts as a hit.

    This leads to three important properties:

    • Matching is exact at the byte level. Paraphrasing with synonyms or changing punctuation invalidates everything after that position.
    • Only the prefix is cached. Any change placed before the shared prefix invalidates content that could otherwise have been reused.
    • Cached state has a lifetime. Idle timeouts or memory pressure trigger eviction, so the hit rate is inherently time-dependent.

    A simplified decision process looks like this:

    1. Input: [System Prompt][Tool Definitions][Conversation History][Current Question]
    2. Hash-compare block by block -> hit blocks H, total blocks T
    3. Hit rate (by token) = H / T
    4. Everything after the first mismatched block is recomputed

    3. Why Coding and Chat Workloads Easily Exceed 96%

    Break down a typical request and the largest portion is usually the most stable one: the system prompt and role setup, the structured tool and function definitions, the code repository context, and the multi-turn history. These can run from thousands to tens of thousands of tokens and barely change within a session. Only the new sentence or function snippet added in the current turn actually varies.

    With token weighting, the denominator is dominated by static content and the numerator is nearly equal to it, so the hit rate naturally approaches 99%. If instead the metric is “how many requests hit any cache,” the number will be noticeably lower, because a single short request with entirely new content is counted as a miss. When you see 96%, confirm the measurement basis first rather than suspecting the platform.

    4. When a High Hit Rate Is Actually a Warning Sign

    A high hit rate is not always good news. Investigate the following cases:

    1. The hit rate stays near 100% while total billed tokens are very small, which may mean the sample size within the measurement window is too small.
    2. The hit rate swings up and down in step with business peaks and troughs, which usually points to cache eviction and concurrency pressure.
    3. You modify the system prompt every time yet the hit rate stays high, which means the edits land after the shared prefix and have no intended effect.
    4. The hit rate is high but response latency does not improve, which means the bottleneck is not in the prefill stage but in decode bandwidth or queueing.

    5. How to Verify the Hit Rate Yourself

    Do not rely on a single number from the platform. Build a controlled comparison instead:

    1. # Pseudocode: build two request groups, A/B, and compare billing and timing
    2. base = system_prompt + tool_schema + history
    3. req_hit = base + "continue" # shares a long prefix with the previous turn
    4. req_miss = "continue" + base # prefix is scrambled, theoretically almost all misses
    5. for name, payload in [("hit", req_hit), ("miss", req_miss)]:
    6. r = client.chat(payload)
    7. print(name, r.usage.prompt_tokens,
    8. r.usage.prompt_cache_hit_tokens, r.elapsed_ms)

    Three observations are enough to draw a conclusion: whether billed tokens drop significantly in the hit group; whether time to first token decreases; and whether the hit rate collapses when the shared prefix is moved to the end. If all three behave as expected, the 96%–99% figure is real and reproducible.

    6. Engineering Practices That Keep the Hit Rate High

    • Fix the prefix order: system prompt, tool definitions, knowledge context, conversation history, current input. Once the order is set, do not change it casually.
    • Put stable content first: move volatile fields such as timestamps, random IDs, and session numbers to the end of the request or replace them with placeholders.
    • Control session pacing: long idle gaps lead to eviction, so keep the cache alive with lightweight requests when necessary.
    • Improve concurrency continuity: route requests from the same session to the same instance to reduce repeated computation across nodes.
    • Build observability: collect hit rate, billed tokens, and time to first token through monitoring, alerting, and logging services, and turn them into a trend dashboard.

    In related practice at Baidu AI Cloud, this capability is typically delivered by combining the model service with general cloud product categories such as monitoring, alerting, and logging. The point is to bring the hit rate into day-to-day cost governance rather than reconciling the bill after the fact.

    7. Conclusion

    For long-prefix, multi-turn, and code workloads, a 96%–99% cache hit rate is normal and desirable. It reflects how well the request construction matches the caching mechanism. What matters is not whether the number is high, but whether the measurement basis is clear, whether the prefix is stable, whether the hit rate is reproducible, and whether it actually translates into savings on the bill and in latency.