Prompt caching
Prompt caching can reuse computation for a compatible repeated prompt prefix. It is different from storing and returning a previously generated answer.
Before you start: Review Memory first. Python-like examples use variables, lists and functions.
Follow the mechanism
Stable prefix
Identify repeated eligible input.
Start with an everyday explanation
A kitchen can prepare shared ingredients once for several meals. Each new order still needs its own final preparation and checks.
See a concrete example
At assumed rates of 1 per million cached input tokens versus 4 uncached, 10,000 eligible tokens cost 0.01 versus 0.04. This is arithmetic with invented rates, not a provider quote.
A claim to question
Caching does not guarantee the same answer or a universal percentage saving.
Try before revealing the answer
Explain the difference between prompt caching, a KV cache and an application response cache.
Show the worked answer
Prompt caching reuses eligible prompt computation across requests. KV state supports token generation. Response caching reuses an answer and needs its own key, authorization and freshness policy.
Now explain the idea to someone else using your own example. If you cannot explain a stage, revisit it before moving on.
Engineering details and trade-offs
Provider rules determine eligible prefixes, minimum length, expiry and billing. Measure cache hits and actual charged usage.
Keep stable instructions before changing content when the provider supports prefix caching. A cached prefix must still be isolated and must not bypass authorization.
Reason through the example
At assumed rates of 1 per million cached input tokens versus 4 uncached, 10,000 eligible tokens cost 0.01 versus 0.04. This is arithmetic with invented rates, not a provider quote.
Implement and test
Explain the difference between prompt caching, a KV cache and an application response cache.
Inspect the reasoning and expected result
Prompt caching reuses eligible prompt computation across requests. KV state supports token generation. Response caching reuses an answer and needs its own key, authorization and freshness policy.
What to measure
State the expected result before changing a control. Record your inputs, compare the observed result and explain one limit of this model. In a real implementation, test the failure case as well as the normal path.
Answer before reading the reference
How do you evaluate whether prompt caching helps?
A defensible answer
Measure eligible repeated tokens, hit rate, effective input cost, latency and expiry behavior under representative traffic. Include cold requests and compare the complete request bill.
Prepare the follow-up
How would a response cache leak data if its key omitted the user scope?
Show follow-up reasoning
A response-cache key needs the authorized user or tenant scope, relevant permissions, source versions, request semantics and model/prompt settings as appropriate. Missing user scope can serve one user another user’s answer. Reauthorize access and define invalidation; prompt caching is a different mechanism.
Use the engineering explanation and worked task above to support your response. Identify which assumptions you would need to verify in production.
Choose a practice depth
- New to GenAI
- Define prompt caching with the everyday example and name its key limitation.
- Applied experience
- Explain the example, implementation choice and a measured failure case. Use the exercise as a small design review.
- Senior or systems depth
- Answer the follow-up, compare alternatives and justify an evaluation or rollout plan with operational constraints.
Self-review your answer
0/4 checks selected. This is self-assessment, not an interview score.
Your explanation and revision notes
Loading local notes…