Module 8 · Lesson 1 of 4

Exact-match caches

Same prompt, same answer

An exact-match cache answers a repeated prompt from storage, but only when every character is the same.

Scene 1 of 4 · The first request

The first "What are your opening hours?" misses the cache, so the model answers and the answer is stored.

Help pageHelp pageYour backendYour backendAnswer cacheAnswer cache1 answer storedLanguage modelLanguage model
  • Help page — healthy
  • Your backend — healthy
  • Answer cache — healthy — 1 answer stored
  • Language model — healthy
Prompts and what the cache found
PromptCache
What are your opening hours? (highlighted)miss: the model answers, the answer is stored
Requests today
1
Model calls
1
  1. The first request. The first "What are your opening hours?" misses the cache, so the model answers and the answer is stored.
  2. The same again. The other 4,999 identical requests that day come straight from the cache, with no model call.
  3. One word more. Adding one word, "today", makes a different prompt, so it misses and calls the model.
  4. Refresh with a TTL. Each answer expires 24 hours after it was stored; the next request after that gets a fresh one.
  5. Now you try. The cache holds the answer to "What are your opening hours?". Send a new prompt. For example: Cache miss: the backend calls the model. The meaning is the same, but the characters differ, and an exact cache compares characters only.

Scene 1 of 4: The first request. The first "What are your opening hours?" misses the cache, so the model answers and the answer is stored.

Key points

  1. The cache key is the whole prompt, character for character.
  2. A repeat answers from storage, with no model call.
  3. One extra word, a capital letter or a date makes a new prompt.
  4. A TTL makes old answers expire, so they refresh.

The simplest stores each and its answer. If exactly the same prompt arrives again, the answer comes from the cache, with no model call.

It cannot match the wrong question, since the prompt must be identical. It can still serve an old answer, so each entry needs a time limit. Hits are also rarer than you might hope: one extra word or a changed date makes a new prompt.

Example. A help page asks the model "What are your opening hours?" 5,000 times a day. An exact cache calls the model once and answers the other 4,999 from the cache.

In system design: Use an exact cache for repeated, fixed prompts, such as a daily summary, and give each entry a so it refreshes.

Check yourself

Why do exact-match caches hit less often than people expect?