Caching Prompts and Responses to Reduce Cost
This lesson covers caching at several levels, prompt prefixes inside Bedrock, complete responses for identical or similar requests and content at the edge, and the trade-offs of each.
Learning outcomes
After completing this lesson, you will be able to:
- Use prompt caching in Amazon Bedrock.
- Cache exact matches with request hashing.
- Use semantic and edge caching.
Prompt caching in Amazon Bedrock
Prompt caching stores the model's processed state for a prompt prefix. The application marks the end of the reusable prefix, such as a long system prompt, tool definitions or a document, with a cachePoint block in the Converse request. The first request writes the cache; later requests with an identical prefix within the cache's time to live (a few minutes, refreshed on each hit) read it, and cached input tokens are billed at a substantially reduced rate and processed faster, lowering latency. Supported models, minimum prefix lengths and the number of checkpoints vary by model. The response's usage shows cache read and write tokens.
r = brt.converse(
modelId="us.amazon.nova-pro-v1:0",
system=[{"text": LONG_POLICY_MANUAL}, {"cachePoint": {"type": "default"}}], # reusable prefix ends here
messages=[{"role": "user", "content": [{"text": question}]}],
)
print(r["usage"].get("cacheReadInputTokens"), r["usage"].get("cacheWriteInputTokens"))Prompt caching helps only when the prefix is identical, so variable content (the user's question, retrieved chunks that change per request) must come after the cache point.
The following diagram shows two requests that share a cached prefix.

When prompt caching pays off
Exact-match caching with request hashing
Exact-match caching stores complete responses keyed by a deterministic hash of the normalised request: model ID, prompt version, inference parameters and the normalised input (trimmed, lowercased where safe). A request whose hash is found returns the stored response without invoking the model. Amazon ElastiCache (Valkey or Redis OSS) gives sub-millisecond lookups; DynamoDB with TTL is a durable alternative. Result fingerprinting hashes outputs to detect duplicates and to deduplicate stored results. Exact caching suits deterministic tasks (temperature 0) with repeated inputs, such as classifying identical product titles.
Building the cache key
Semantic caching and edge caching
Semantic caching handles paraphrases: the question is embedded, a vector search finds previously answered questions above a similarity threshold, and the stored answer is returned. It can be built with vector search in ElastiCache or OpenSearch. The threshold trades hit rate against the risk of returning an answer to a subtly different question, so it is tuned on real queries, and personalised or time-sensitive answers are excluded.
Edge caching with Amazon CloudFront serves non-personalized generated content, such as product descriptions or FAQ answers exposed through GET requests, from edge locations close to users; Lambda@Edge or CloudFront Functions can normalise cache keys. All caches need invalidation tied to data freshness: expire entries when source documents, prompts or models change. The following table compares the strategies.
| Strategy | Reuses | Best for |
|---|---|---|
| Prompt caching | Processed prompt prefix inside Bedrock | Long, repeated system prompts, tools or documents |
| Exact-match cache (hash key) | Complete responses for identical requests | Deterministic, repetitive requests |
| Semantic cache | Responses for similar questions | FAQ-like traffic with paraphrases |
| Edge cache (CloudFront) | Responses at edge locations | Non-personalized content for many users |
| Pre-computation | Answers generated in advance | Predictable queries |
The following diagram shows two caches, a semantic cache and prompt caching, working together for a product assistant.

Which cache fits?
Repeated questions
A public product assistant receives thousands of daily questions; analysis shows that 40% are paraphrases of 200 common questions, and every request includes the same 8,000-token product manual excerpt.
A semantic cache answers paraphrased common questions without invoking the model, and prompt caching with a cache point after the manual excerpt lowers the cost and latency of the remaining calls. Cache entries expire when the manual is updated.
With prompt caching, where should variable content go relative to the cachePoint?
Show answer
After it. The identical prefix before the cachePoint is cached, and anything that changes must follow it.
Exam Tips
Remember for the exam
- Long, identical prompt prefix: prompt caching with cachePoint; variable content after it.
- Identical requests: exact cache keyed by a hash of model, prompt version, parameters and input.
- Paraphrased questions: semantic cache with a tuned similarity threshold.
- Invalidate caches when sources, prompts or models change.