LLM Response Caching Without Storing Sensitive Data
LLM response caching stores a model's answer and serves it again when the same request comes back, so you skip the provider call, its cost and its latency. On an AI gateway the cache is also a governance surface. A naive cache keeps a copy of whatever personal data was in the prompt and the answer, and it can keep charging you for calls that never happened. In DVARA, an AI gateway that governs model, tool and agent-to-agent calls, the response cache sits inside the same governed path as policy and PII checks: personal data is stripped before anything is cached, a hit costs $0, and a cached answer is checked by today's rules before it is served.
Updated November 11, 2026 for DVARA 1.13.0.
Exact matching or semantic matching?
An exact-match cache serves a stored answer only when the new request is the same request. It is safe: the answer was generated for exactly this input.
A semantic cache embeds the prompt as a vector and serves a stored answer when a new prompt is close to a stored one by cosine similarity, above a threshold. It promises more hits, because "What's your refund policy?" and "How do I get my money back?" could share one answer.
The catch is that similarity measures how related two prompts are, not whether they ask the same thing. We measured it over 20 prompt pairs. The three highest-scoring pairs were all ones that must not share an answer: two negations and a word-order swap. Precision never rose above 0.38 at any threshold. So in DVARA semantic serving is off by default, and the semantic backend serves on an exact key match unless you switch similarity serving on. Switch it on only where a related answer is acceptable, such as an FAQ bot, and never where a wrong answer is a correctness or safety problem.
How do you keep personal data out of the cache?
Strip it before the cache is touched. DVARA makes a cache-safe copy of each request in which detected personal data is replaced with irreversible placeholders scoped to the workspace. That copy is used for both the lookup and the write, so the cache never holds the raw values.
This is separate from what your workspace's PII action does to the request that goes to the provider. The cache copy stays irreversible even when that action is TOKENIZE, and a BLOCK stops the request before the cache is reached. Your workspace's PII settings decide what is detected.
Why must a cached answer be checked again?
Because the rules may have changed since it was stored. A hit runs the same output checks a fresh answer runs: response PII scanning, output guardrails, schema validation and grounding detection. If those checks refuse a cached answer, the entry is evicted. When the gateway applies a new configuration, the response cache empties, so an answer stored under old rules is never served under new ones.
Why must a cache hit cost $0?
No provider call happened, so nothing was spent. A cache that books the original call's cost on every hit erases the savings it exists to create.
In DVARA a hit is recorded as served usage, marked as a hit, with no upstream cost. You keep the volume for reporting, and spend reflects only real provider calls. That is what makes caching a cost governance lever and not only a latency trick. The hit's GATEWAY_RESPONSE audit record also carries cache_status and cache_similarity (1.0 for an exact-key hit), so a disputed cached answer can be explained from the audit trail.
Hits are also fast, because the provider's generation time drops out. Streaming requests bypass the cache, so this applies to non-streaming calls only.
What can go wrong?
- Stale answers. A cached answer can go out of date. Entries expire after
3600seconds by default, and each workspace can scope which models it caches. - Wrong answers from near-matches. Only a risk with similarity serving on. Keep it off where correctness matters.
- Personal or computed answers. Don't cache responses that are specific to one user or must be computed fresh.
What do you get in each distribution?
Every cache is off until you turn it on.
| Open Source | Enterprise | |
|---|---|---|
| Backend | Exact match, in memory, one process | Semantic backend, shared across gateway pods |
| How you turn it on | dvara.llm-gateway.cache.in-memory.enabled: true (default false); every workspace is then cached, in separate entries | Each workspace turns its own cache on, from Cost → Cache or its settings |
| Serves on | An exact key match | An exact key match, unless you set dvara.llm-gateway.cache.semantic.similarity-serving: true |
| PII stripped before lookup and write | Yes | Yes |
With similarity serving on, the default threshold is 0.92 and each workspace can set its own. The default embedding is a character-trigram hash, which catches close rewordings but not synonyms; an in-process neural model is an opt-in.
A checklist for any LLM cache
- Personal data is stripped before the cache is read or written.
- A hit books $0 upstream cost, and still shows up in usage.
- Cached answers pass today's output checks on every hit.
- Entries expire, and caching can be scoped per workspace and model.
- Semantic serving is a deliberate choice per use case, not a default.
Try it
DVARA keeps a tamper-evident audit trail, runs policy and personal-data checks on every call, and stops agents that loop; caching, routing and failover come standard. The full reference, including the similarity measurement, is in the response caching docs.