Reducing Cost and Latency with Prompt, Semantic and Response Caching
This lesson distinguishes prompt, semantic and response caching, which reuse the repeated work of multi-agent systems to cut cost and latency, and the risks of each.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how prompt caching reuses a shared prefix.
- Describe semantic caching and the risk of serving wrong answers.
- Cache deterministic operations with response caching.
Prompt caching
Prompt caching is performed by the model service. When a request begins with the same token sequence as a recent request, the service reuses the computation for that prefix, which reduces latency and bills cached input tokens at a discount. For Azure OpenAI models, caching applies to prompts of at least 1,024 tokens, in increments after that, and requires an identical prefix; a single changed token early in the prompt prevents reuse. The response usage reports cached tokens. Designing for prompt caching means placing instructions, tool definitions and fixed examples first and variable content last, and keeping them byte-for-byte stable.
The following diagram compares a cache-friendly prompt with a cache-hostile one.

Prompt caching
Semantic caching
Semantic caching stores a response together with the embedding of the request. When a new request's embedding is within a similarity threshold of a cached one, the cached response is returned without calling the model. The API Management AI gateway provides semantic cache lookup and store policies backed by Azure Managed Redis, with an embeddings deployment to vectorize requests. The threshold trades hit rate against the risk of returning an answer to a subtly different question. Semantic caching suits frequently asked, user-independent questions.
The following diagram shows a semantic cache lookup.

Semantic cache decisions
Response caching
Response caching stores exact results of deterministic operations keyed by their inputs: retrieval queries, tool calls such as currency rates or product details, and embeddings of unchanged text. It uses a TTL that matches how quickly the data changes. The following table compares the three types.
| Cache | What is reused | Where | Main risk |
|---|---|---|---|
| Prompt caching | Computation for an identical prompt prefix | Model service | None to correctness; only works with stable prefixes |
| Semantic caching | Answers to similar requests | API Management with Redis, or custom | Wrong answer for a different question; data leakage across users |
| Response caching | Exact tool or query results | Application cache, Redis | Stale data beyond TTL |
Caches must respect security boundaries. Answers that depend on the user's permissions, identity or tenant must be keyed by that scope or excluded from shared caches, otherwise one user can receive another's data.
Which kind of cache?
Reducing cost of an FAQ agent
An HR agent answers 50,000 questions a month. About 60% are variants of 30 common policy questions whose answers are the same for everyone. The agent's 4,000-token instructions are identical on every call, but the current date is inserted at the top.
Moving the date to the end of the prompt makes the 4,000-token prefix stable, so prompt caching applies to every call. A semantic cache in API Management serves the common policy questions without model calls. Questions about a person's own leave balance must bypass the shared cache, because their answers depend on the user.
Why must permission-dependent answers never come from a shared cache?
Show answer
One user could receive an answer built from data that only another user may see.
Exam Tips
Remember for the exam
- Prompt caching needs an identical prefix of at least 1,024 tokens; put variable content last.
- Semantic caching suits user-independent questions; tune the similarity threshold.
- Never serve permission-dependent answers from a shared cache.