
Use prompt and prefix caching for stable large prefixes, pair it with KV caching for token-level reuse within a request, and add a multi-tier offload policy for long contexts. The engineering work spans several trade-offs: time to first token (TTFT), the cost of cache writes and reads, answer correctness under semantic reuse, and privacy across tenants. Eviction choices like LFU or ARC and an I/O-aware restore policy, which we cover below, decide how well that mix performs. For teams running this inside sovereign or air-gapped infrastructure, Forge AI Deployment builds the operational layer around it.
TL;DR:
- Start with LFU or ARC, not FIFO or LRU; adaptive policies improved hit rates and time to first token, especially on document question answering workloads.
- Some cache checks look back only 20 blocks, and any upstream prompt or tool change invalidates cached blocks downstream of the breakpoint.
- Offload evicted KV blocks across GPU memory, CPU memory, and disk, then choose restoration or recomputation based on GPU load, storage bandwidth, and latency targets.
- Salt every cache key with a tenant or session identifier, monitor timing and eviction probes, and validate semantic matches with a judge before serving them.
- For provider prompt caching, verify model support and compare cached_tokens with cache_creation_input_tokens, since cache reads and writes receive different billing.
Table of Contents
- LLM caching types: KV cache, prompt caching, and semantic matching
- How caching works: blocks, prefix hashing, and cache keys
- Eviction policies: LRU, LFU, ARC, and when to go adaptive
- Offloading and the restore versus recompute decision
- Security, privacy, and correctness controls for caches
- Implementation patterns: in-memory, Redis, disk, and provider caching
- Best-practices checklist and what to monitor
- Operating caches in sovereign and air-gapped deployments
- What the research gets right and where teams overcorrect
- How Forge helps teams ship production-grade LLM caching
- FAQ
- Sources
LLM caching types: KV cache, prompt caching, and semantic matching
A KV cache stores the key and value tensors each attention layer computes for tokens already processed, so generating the next token does not require recomputing attention over the entire sequence. This turns per-step attention cost from quadratic to linear in sequence length, which is why it matters for any long-context inference workload.
Prompt or prefix caching works at a higher level: it stores the processed representation of a prefix, a system prompt, a document, a tool schema, so a later request sharing that prefix skips reprocessing it entirely.
Exact-match and semantic caches solve a different problem: reusing full responses.
- Exact-match caches hash the request and return a stored response on an identical hit, failing silently on any whitespace or ordering difference.
- Semantic caches use embedding similarity to catch paraphrased repeats, but they risk returning a response that is close in meaning but wrong for the new query.
How caching works: blocks, prefix hashing, and cache keys
KV caches are organized into blocks, fixed-size chunks of tokens per layer, stored in a pool so the serving engine can allocate, reuse, and evict at block granularity rather than per token. When two requests share a prefix, the engine can reuse the matching blocks and only compute the diverging tail, which is what makes partial reuse possible even when requests are not identical.
Implementing this correctly means handling several mechanics:
- Prefix hashing: the system hashes the prefix content to detect whether a matching cache entry already exists before deciding to reuse or recompute it.
- Breakpoints and lookback: explicit
cache_controlbreakpoints mark where a cacheable prefix ends, and the cache check only looks back a limited window, 20 blocks in Anthropic’s implementation, before giving up and treating the prefix as new. - Invalidation: any edit upstream of a breakpoint, including a changed system prompt or reordered tool definitions, invalidates every cached block downstream of it.
Provider prompt caching reports cache_creation_input_tokens and cached_tokens separately from standard input tokens, and writes to the cache are billed differently than reads, which means a badly placed breakpoint can increase cost instead of lowering it.
Eviction policies: LRU, LFU, ARC, and when to go adaptive
Eviction policy decides what survives in a capacity-constrained cache, and the choice has measurable consequences on hit rate and query cost. A systematic study across workloads, capacities, and encoders found that LFU is a strong, simple baseline for LLM caches, while naive FIFO or basic streaming variants tend to underperform and cost more per query because they evict entries purely by arrival time, ignoring how often or how recently they were actually used.
Adaptive hybrid approaches close more of the gap. Recency and frequency adaptive caching (ARC-style policies) integrated into LLM serving improved cache hit rate and reduced time to first token over naive LRU, with the largest gains on document-QA workloads and smaller but still measurable gains on conversational workloads.
A practical rollout sequence looks like this:
- Start with an LFU or ARC baseline rather than FIFO or raw LRU.
- Instrument hit rate and session locality before tuning further.
- Move to adaptive partitioning only when workload mixes show clear hotspots.
Pro Tip: Log eviction policy alongside hit rate from day one, so a later policy change has a clean before-and-after comparison instead of a guess.
Offloading and the restore versus recompute decision
GPU high-bandwidth memory runs out fast on long contexts, which is why production systems cascade evicted KV blocks through a multi-tier hierarchy: GPU HBM, then CPU DRAM, then disk. Offloading extends effective KV capacity well past what fits on the accelerator, but it introduces a new decision every time a block is needed again: restore it from the lower tier or recompute it from scratch.
Research on KV-cache restoration found that static eviction policies often leave performance on the table here. An I/O-aware policy that weighs GPU compute availability, storage bandwidth, and latency SLOs at decision time can substantially improve throughput compared to a fixed restore-always or recompute-always rule.
Deployment-level configuration options map directly to this decision:
evictionPolicyset tolruorarcon the CPU offload tier.host_cache_sizeto bound how much CPU DRAM the offload tier can consume.- Ordered disk tiers behind DRAM, backed by ephemeral node-local disks for short-lived sessions or persistent volumes when cache state needs to survive a pod restart.
Security, privacy, and correctness controls for caches
A cache that serves one tenant’s data to another tenant’s request is a breach, not a bug, so cache keys need tenant isolation built in from the start.
- Salt cache keys with a tenant or session identifier so an identical prompt from two different tenants never resolves to the same cache entry.
- Treat semantic cache hits as candidates, not answers: validation research shows semantic caches work best on genuinely repetitive queries and need an LLM judge or similar check before a hit is served, especially for high-consequence responses.
- Watch for timing side channels, where cache hit latency differs enough from a miss to leak whether another tenant asked a similar question, and for eviction-based probing, where an attacker forces evictions to infer cache contents.
Pro Tip: Treat the cache as part of your data boundary, not a performance add-on bolted on afterward; review it with the same scrutiny as the database. Our prompt injection defense and data leakage write-ups cover adjacent controls worth pairing with cache isolation.
Implementation patterns: in-memory, Redis, disk, and provider caching
The backing store depends on how much state needs to survive and who needs to see it.
- In-memory caches fit a single worker process or genuinely ephemeral sessions, with the tradeoff that nothing survives a restart and nothing is shared across replicas.
- Redis fits multi-worker deployments that need a shared, fast cache, since every replica can read and write the same keys with low latency.
- Disk or object storage like S3 fits long-lived or cross-replica persistence, trading some latency for durability and scale beyond memory limits.
Provider-level prompt caching adds a different axis: automatic caching applies cache_control at the top level and lets the provider decide what to cache, while explicit breakpoints give control over exactly which prefix boundary gets cached, which matters when a long stable system prompt sits ahead of variable user content.
- Pre-warm a prefix before traffic arrives by sending a request with
max_tokens: 0, which populates the cache without generating output. - Confirm the target model actually supports prompt caching before relying on it in production.
- Check
cache_creation_input_tokensandcached_tokensin each response to confirm hits are landing where expected, rather than assuming the breakpoint worked.
Best-practices checklist and what to monitor
A short runbook covers most production caching decisions:
- Pick a baseline eviction policy, LFU or ARC, before tuning anything else.
- Place explicit breakpoints on the longest stable prefixes: system prompts, tool schemas, shared documents.
- Pre-warm critical prefixes ahead of expected traffic spikes.
- Enable tenant-salted cache keys everywhere multi-tenant requests pass through the cache.
- Set TTLs from actual cost and hit-rate math, not a default value copied from another service.
Adaptive recency-frequency caching improved hit rate and reduced TTFT over naive LRU, with the strongest gains on document-QA style workloads. That is the kind of number worth reproducing against your own traffic before trusting it.
Monitor cache hit rate, cached_tokens, TTFT, P95 and P99 latency, cache write and read costs, and the ratio of restore-versus-recompute decisions under offload. Validate with an LLM judge for substitutability on semantic hits, and before testing cache behavior in production, running real queries against candidate configurations surfaces problems a synthetic benchmark misses. Run workload simulations that force evictions and confirm tail latency holds up once the offload tiers get exercised.
Operating caches in sovereign and air-gapped deployments
Sovereign and air-gapped environments push every one of these decisions toward the conservative end: deterministic tenant salting, strict isolation boundaries, and limited semantic-cache use since auditability and zero-exfiltration goals leave little room for a cache that blurs tenant boundaries or returns an unverified near-match.
We build operational runbooks and secure, on-prem deployment patterns for sovereign AI deployments.
What the research gets right and where teams overcorrect
The strongest evidence here points away from exotic policy design and toward instrumentation. LFU and ARC-style hybrids consistently beat naive LRU and FIFO, but the gap between a good policy and a great one is smaller than the gap between measuring hit rate and not measuring it at all.

Where conventional advice falls short is semantic caching. It gets pitched as a drop-in latency win, but the substitutability problem is real: a semantically similar query is not the same query, and treating a semantic hit as equivalent to an exact match is how a cache quietly starts serving wrong answers. Teams that validate semantic hits with a judge model catch this; teams that do not usually find out from a user complaint.
The restore-versus-recompute decision deserves more attention than it gets. Most teams pick one rule and apply it everywhere, when the right choice depends on GPU load, storage bandwidth, and the SLO for that specific request path. If there is one place to prioritize first after getting basic eviction and breakpoints right, it is building that decision as a policy rather than a constant.
— John Ezzell, Founder
How Forge helps teams ship production-grade LLM caching
Getting cache salting, I/O-aware offload policies, and prompt-caching breakpoints right inside a regulated environment is a different problem than getting them right in a demo. We design and operate sovereign AI systems inside infrastructure our customers control, including air-gapped networks, and that work covers secure local deployment, custom model integration and optimization, private AI assistant rollout, sovereign MLOps and runtime orchestration, and ongoing performance tuning.

As an official webAI systems integrator, we bring private and air-gapped deployment, webAI Personas, the Intelligence Delivery Network, and webAI Frontline into production, so frontline teams get fast, source-backed answers from large technical document libraries fully offline.
If your team needs sovereign AI deployment and operational support, talk to us about our solutions.
FAQ
What is the difference between KV caching and prompt caching?
KV caching stores the key and value tensors a model computes per attention layer so it avoids recomputing them for tokens already generated, cutting per-step attention cost from quadratic to linear. Prompt caching stores a processed prefix, like a system prompt, so a later request sharing that prefix skips reprocessing it, and the two typically work together rather than as substitutes.
Should I use a semantic cache for my LLM application?
A semantic cache helps when queries are genuinely repetitive in meaning, not just wording, but raw semantic hit rates can drop sharply once answers are checked for correctness. Validate hits with an LLM judge before serving them, especially for high-consequence responses, rather than assuming a similarity match is a correct one.
Which eviction policy should I start with for an LLM cache?
Start with LFU or an adaptive hybrid like ARC rather than FIFO or plain LRU, since adaptive recency-frequency policies have shown improved hit rates and reduced time to first token over naive LRU in serving workloads. Instrument hit rate and session locality early, then revisit the policy once real traffic patterns are visible.
Should evicted KV cache blocks be restored or recomputed?
Neither rule wins universally: an I/O-aware policy that weighs GPU compute, storage bandwidth, and latency targets at decision time outperforms a fixed always-restore or always-recompute approach. Static policies tend to leave throughput on the table, particularly as context length and offload tier count grow.
How do I prevent cross-tenant data leakage through an LLM cache?
Salt every cache key with a tenant or session identifier so identical prompts from different tenants never resolve to the same stored entry. Pair that with monitoring for timing side channels and eviction-based probing, since both can leak information about other tenants’ cached content even without a direct data return.
Sources
- LLM KV-cache: To Restore or To Recompute, That Is the Question | Proceedings of the 18th ACM Workshop on Hot Topics in Storage and File Systems
- Which Eviction Policy Should an LLM Cache Use? A Systematic Study Across Workloads, Capacities, and Encoders
- KV Cache Offloading | KServe
- Prompt caching