1. Start with a use case: employee travel support
An enterprise launches an AI assistant to help employees prepare travel-expense claims. Employees upload receipts, ask which documents are required, check meal limits and follow up on reimbursement. The workflow combines approved policies, document extraction, live claim records and finance controls.
Many requests repeat work: the same policy is read again, the same receipt is parsed again and the same general question is answered in different words. But not everything is reusable. “Which receipts are required for domestic travel?” is a policy question. “Has my claim been paid?” depends on a particular employee and a current financial record.
I would start by separating those paths. Reuse stable policy processing; consider caching validated general guidance within the same policy and access scope; fetch current claim status under the employee’s authorization. Submitting a claim or releasing payment stays on a controlled action path—not a cached-answer shortcut.
First decide what is safe to reuse.
Caching is a system-design decision, not just a latency setting. For each step, define the reused artifact, its scope, its freshness requirement and the consequence of a wrong hit.
2. “Caching” can mean six different things
A cache stores something expensive to recreate. In an LLM workflow, that “something” might be a complete answer, a model’s input computation, a document embedding or a database read. These save different kinds of work.
| Cache | What is reused | LLM generation? | Main condition |
|---|---|---|---|
| Prompt / prefix cache | Unchanged model input prefix and its computation | Yes: new suffix and output | Exact prefix; provider eligibility and retention |
| Exact-response cache | A previously validated complete answer | No, on a safe hit | Same relevant request context, versions and access scope |
| Semantic-response cache | An answer to an equivalent, differently worded request | No, on a safe hit | Similarity + answer-equivalence and metadata checks |
| Embedding / preprocessing cache | Vectors, parsed text, OCR or other derived artifacts | Usually yes, for the final answer | Content hash + processing / model version |
| Retrieval cache | Authorized document IDs, snippets or ranked results | Usually yes, for generation | Query, filters, corpus version and current permissions |
| Read-only tool-result cache | A reusable API / database read result | Depends on the workflow | Freshness window, entity, arguments and authorization |
In-memory, distributed, hybrid and edge caching describe where a cache lives. Exact matching and semantic matching describe how a reusable item is found. A distributed cache can support either. A vector database can help find semantic candidates, but it does not decide whether serving an answer is safe.
3. Prompt caching: avoid processing the same prefix again
At the model-serving layer, prompt caching usually means prefix caching: reuse computation for an unchanged beginning of the input. In transformer-based systems, this commonly involves reusable attention key/value states. The provider still processes the new suffix and generates a new answer.
For the travel assistant, put stable instructions, stable tool definitions and an authorized, versioned policy bundle before the changing employee question, where the API’s message structure allows. Two different questions can benefit from the same prefix. The prefix must match exactly; the entire request does not need to be identical.
How to make it work
- Keep the reusable beginning stable. Avoid putting a fresh timestamp, random identifier or changing user question before a large shared block.
- Use provider-supported controls. Follow the model’s automatic caching, explicit breakpoint or managed-context mechanism. Minimum token counts, lifetimes and supported content vary.
- Preserve correctness over hit rate. Update a changed policy even if that causes a miss. Do not rearrange messages in a way that changes their meaning, trust boundary or permissions.
- Verify reuse from usage telemetry. Inspect cached-input tokens and creation/read usage where available; repeated requests alone do not prove a hit.
This can reduce prefill latency—the work before generating tokens—and time to first token. It does not automatically speed up every output token. A response dominated by long generation, slow tools or retrieval may show a smaller end-to-end improvement.
Trade-off: writes, storage or retention can cost money, depending on the provider. Short or infrequently repeated prefixes may not qualify or pay back their setup cost. Self-hosted prefix caching also consumes limited accelerator memory and interacts with scheduling and eviction; it is not unlimited free capacity.
4. Exact-response caching: reuse the answer only for the same context
An application-level response cache stores a complete validated answer. A safe hit can avoid generation entirely. This suits repeated, stable FAQ requests or deterministic summaries of the same versioned source.
“Exact” must mean more than identical question text. The same words can require different answers for different regions, policy dates, employee entitlements or conversation histories. A practical key includes the relevant tenant/access scope, normalized request, relevant conversation context, policy or corpus version, prompt version, model identity and answer-affecting settings.
Use a canonical serialization and a cryptographic hash rather than a concatenation that can be ambiguous. Keep the metadata needed for validation and invalidation alongside the record. A hash is not encryption or anonymization: cached payloads still need access controls, encryption and retention rules.
Trade-off: a broader key increases reuse but can mix contexts; a narrower key is safer but reduces hits. Normalize carefully—do not erase negation, amounts, dates, currencies or entity IDs. And if a user asks for a fresh creative variation, silently returning the same output may violate the request even when the text matches.
5. Semantic caching: find similar questions, then prove the answer fits
Semantic response caching searches by meaning rather than exact words. Convert an eligible request into an embedding, search a scoped vector index and retrieve candidate answers above a chosen similarity threshold. That is candidate discovery, not permission to return the first result.
“Which documents must I attach to a domestic travel claim?” and “What supporting paperwork is required for domestic travel reimbursement?” may be equivalent under the same policy. But “Can I claim meals with a receipt?” and “Can I claim meals without a receipt?” can have very similar embeddings and very different answers.
Potentially reusable
Same intent, same policy version, same region, same eligibility and no private claim-specific context. Validate the candidate’s coverage and evidence before serving.
Reject the apparent match
Different amount, missing receipt, another employee’s claim, changed policy, time-sensitive status or a request to take an action. Similar wording is not enough.
Filter by tenant, current access scope, language, policy version and relevant structured entities. Check expiry and whether the candidate actually covers the requested facts. For sensitive domains, prefer deterministic eligibility rules and narrow cacheable intents; if equivalence is uncertain, use the fresh path. Adding a second LLM to validate every hit can consume much of the intended saving.
Threshold tuning is an evaluation problem. A lower threshold can increase hit rate and false hits. A higher one can reject useful paraphrases. There is no universally safe “0.85”: scores depend on the embedding model, distance metric, dataset and index. Test accepted matches, near misses and clearly unrelated requests separately.
Trade-off: embedding, vector search and validation add cost and latency, especially on misses. Changing the embedding model requires re-embedding or partitioning the index by version; changing policies or generation behavior requires reviewing or invalidating affected cached answers. Semantic caching is not a replacement for RAG or an authoritative database.
6. Cache supporting work, not just the final answer
- Parsing and embeddings: reuse OCR results and document vectors keyed by content hash plus extraction, chunking and embedding versions. A changed receipt, parser or embedding model needs a different artifact.
- RAG retrieval: cache expensive searches for a query, filters and corpus/index version. Store source IDs and provenance; recheck access and current source validity before reuse. A retrieval hit usually still leads to generation.
- Read-only tools: cache slowly changing reference data, such as an approved category list. Live exchange rates, balances or claim status need freshness guarantees suited to the business—not a blanket long TTL.
- Agent substeps: reuse stable classification or planning inputs only when state, tool availability and constraints still match. Reusing an old plan after the world changes can produce the wrong action.
A local in-process cache is fast but separate across instances and lost on restart. A distributed key-value cache shares results across replicas but adds a network hop, operational cost and concurrency concerns. A semantic layer needs vector search and filterable metadata. Combine layers only when their added complexity is justified.
Do not cache action execution as if it were reusable knowledge. Claim submission and payment require durable transaction controls and idempotency. An idempotency key prevents one operation from being executed twice; it does not authorize replaying a different person’s result or skipping a new approval.
7. Put the layers into a safe architecture
The order matters. Authenticate and classify first. Check response caches only for eligible requests. Treat exact and semantic hits as candidates that must pass current access, freshness and validity checks. On a miss or rejected candidate, retrieve authorized evidence, call required tools and generate a new response—with provider prefix reuse where applicable.
Validate grounding, required output schema and business rules before admitting a response to the cache. Store evidence, source versions, eligibility metadata, expiry and generation configuration with approved entries. A cached answer must retain its supporting citations—not just fluent text.
If the cache service fails, a bounded bypass to the normal authorized workflow can preserve availability. It must not bypass security checks. Protect the fallback from overload with timeouts, rate limits and circuit breakers. On popular misses, use request coalescing or bounded locks to avoid a cache stampede: many callers generating the same missing result at once.
8. Measure the whole bill—not the discount headline
A 90% discount on cached input is not a 90% reduction in total application cost. Uncached input, output generation, cache writes, storage, embeddings, retrieval, tools and validation still matter.
Illustrative prompt-cache calculation
Fictional rates, not a provider quote: input $2 / million tokens; cached input $0.20 / million; output $8 / million. Assume 8,000 reusable input tokens, 2,000 new input tokens and 1,000 output tokens.
- Without a cache hit
- 10,000 × $2 / 1M + 1,000 × $8 / 1M = $0.028
- With an eligible warm prefix hit
- 8,000 × $0.20 / 1M + 2,000 × $2 / 1M + 1,000 × $8 / 1M = $0.0136
That is about 51% lower model cost for this warm request, not 90%. The example excludes cache creation, storage and other workflow costs and assumes equal output length. Cold requests and partial hits change the average.
For response caching, estimate the average as lookup cost + hit rate × hit-validation cost + miss rate × fresh-path cost + amortized write/storage cost. Include embeddings and equivalence checks in the appropriate path. Exact and semantic hits are sequential, not percentages to add together: a semantic lookup sees only requests not already served by the exact cache.
For prompt caching, break-even depends on how often a prefix is reused before expiry and the model’s write/read/storage pricing. Measure actual token usage and bills rather than assuming every eligible request hits.
Track time to first token, total completion time and p50/p95 latency separately, split by cache layer, cold/warm state and hit/miss. A high hit rate can coexist with slow misses or unacceptable false hits. The business metric is cost per correct, authorized completed task—not cost per response alone.
9. What the industry is doing—and what the evidence means
Two distinct approaches are visible in current documentation: providers reuse input computation inside model serving, while application platforms and AI gateways reuse selected responses and intermediate results outside the model. They can work together; they should not be described as the same mechanism.
OpenAI
Documents prompt-prefix reuse on supported models. Automatic behavior, explicit controls, eligible lengths, retention and pricing vary by model/API. Verify cached-input usage rather than assuming a hit.
Anthropic
Documents automatic and explicit cache-control mechanisms for supported Claude models. Prefix structure and breakpoints matter; cache writes and reads can have different rates, and duration options vary.
Google Gemini
The generateContent documentation covers implicit reuse and explicit cached-content resources with a lifetime. Explicit caching includes storage-duration cost. Support differs across models and API surfaces.
Application gateways
Oracle describes exact, prompt and semantic caching; TrueFoundry and Tetrate discuss response reuse and gateway-level controls. Centralization can help with policy and telemetry, but tenant isolation and answer validity still need explicit design.
LogicMonitor reports that a semantically similar repeat request had 50% lower response time in a controlled Catchpoint lab test. That is a vendor-reported result for that test, not a forecast for every enterprise workflow. Real gains depend on repetition, lookup overhead, output length, data change frequency and the correctness standard.
Published lists also mix storage placement, response matching and compute optimizations. Keep these categories separate. Quantization, autoscaling and federated learning are not themselves semantic or prompt caching. Likewise, an “80% savings” headline is not a production guarantee.
10. Production checklist: correctness before hit rate
Build a representative evaluation set before enabling broad reuse. Include genuine paraphrases and difficult negative pairs: changed amounts, negation, region, dates, employee IDs, follow-up pronouns and policy versions. Compare cached and uncached paths against approved expected behavior—not just matching text.
- Define cacheable intents. Start with stable, low-risk reads. Exclude dynamic or personalized results unless their freshness and identity constraints can be enforced.
- Version dependencies. Track source, prompt, model, embedding, schema and tool versions as applicable. Invalidate on meaningful changes; do not rely only on a TTL.
- Recheck authorization. Test cross-tenant isolation, revoked roles, deleted sources and account changes. A cache entry never grants access.
- Protect data and writes. Restrict cache admission to validated trusted results; defend against cached prompt-injection content and poisoned answers. Minimize PII and enforce encryption, retention and deletion across replicas and backups as required.
- Measure quality. Track false-hit rate, accepted-hit correctness, grounding, stale responses and task success. Similarity scores are diagnostic signals, not accuracy scores.
- Measure performance and spend. Compare cold, warm, hit and miss paths; include provider usage, embedding/search fees, storage, validation and infrastructure.
- Exercise failure modes. Test expiry, eviction, cold starts, stampedes, network failures, missing citations and embedding-model changes. Bound fallback traffic.
- Roll out gradually. Use shadow evaluation or sampled fresh-path comparisons with appropriate privacy and cost controls. Set risk-based thresholds, an owner, alerts and a cache-disable switch.
The practical takeaway
Use prompt caching for stable input processing. Use exact-response caching for truly equivalent requests. Add semantic caching only where answer equivalence can be evaluated and enforced. Cache supporting work where it helps. A faster stale answer is not an optimization—it is a system failure.
References and further reading
Documentation and supplied references reviewed on October 13, 2026. Provider details change by model and API; check current documentation and pricing before implementation. The Medium reference was available only as a public excerpt. Vendor tests and headline savings are not treated as universal guarantees.
- OpenAI: Prompt caching documentation
- Anthropic: Prompt caching documentation
- Google: Gemini generateContent context caching
- Oracle: Importance of Caching in Building a Generative AI Platform
- LogicMonitor: Semantic Caching for AI Agents—How It Works and Why Monitoring Matters
- TrueFoundry: Semantic Caching for Large Language Models
- Tetrate: Caching Strategies for AI Applications
- Serverion: Top 7 Data Caching Techniques for AI Workloads
- Medium: Slash Your AI Costs by 80%—The Complete Guide to Prompt Caching (public excerpt)



