Caching strategies for LLM apps
For engineers
Choosing between provider prompt caching, exact-match response caches, semantic caches and tool-result caches, and keeping them from serving stale, leaked or wrong answers
110 questions across four stages: Understand, Apply, Solve and Judge.
Try 5 questions
Practice items, not counted towards your mastery. No account needed.
Check yourself · 1 of 5
A provider prompt-cache hit happens on a request. What still runs?
Check yourself · 2 of 5
A response cache is keyed on the user message only. What breaks first when the team edits the system prompt?
Check yourself · 3 of 5
What does raising a semantic cache's similarity threshold do?
Check yourself · 4 of 5
Which agent tool call must never be served from a cache?
Check yourself · 5 of 5
A cached answer says "Your balance is 240" and the key is the question text. What is the main risk?
Topics
- Where provider prompt caching fits in the stack4 min read · Provider prompt caching makes a repeated prefix cheaper and faster but still runs the model; comparing it with caches that skip the call, and tracking hit rate per route
- Exact-match response caching with safe keys5 min read · Caching whole responses for repeated deterministic requests, with a key that includes model, prompt version, parameters, tools and the user or tenant scope, plus a time to live
- Semantic caching by embedding similarity5 min read · Embedding each query, returning a cached answer when a near neighbour passes a similarity threshold, and tuning that threshold on labelled query pairs to keep false hits low
- Caching tool and retrieval results in agents5 min read · Which tool calls, search results and embeddings in an agent run can be reused, for how long, and which must always be fresh because they read live state or cause side effects
- Stale, leaked and wrong cached answers5 min read · Answers that outlive the source they came from, personalised answers served to another user, a cached hallucination repeated to thousands, and invalidation on prompt or model change
Start here
- Prompt caching (Claude docs) (opens in a new tab)DocsFree
How a cached prefix is marked, how long it lives and how cache read and write tokens are reported.
- Prompt caching (OpenAI API docs) (opens in a new tab)DocsFree
Automatic prefix caching on another provider, with the rules for what counts as a repeated prefix.
- RedisVL: semantic caching for LLMs (opens in a new tab)DocsFree
A working semantic cache: distance threshold, time to live and filters for scoping entries.
Scenarios
Helps to know first
110 questions · last verified 2026-12