LLMscore
Prompt caching
Reuse the processed prefix of a prompt across calls: cheaper and faster input.
What it is and why it exists
If many requests start with the same tokens (system prompt, tools, a long document), the provider can keep the computed KV cache for that prefix. Cached input tokens are billed at a fraction of the normal rate and cut TTFT. It only works on an exact, identical prefix.
Quick prototype
Turn it on (or rely on automatic caching) and check the cached-token count in the usage block.
In production, at scale
Order the prompt from most static to most dynamic: tools → system prompt → reference docs → conversation → latest message. Never put timestamps or user IDs at the top. Measure cache hit rate per route.
Vendors and tools
| Anthropic prompt caching | Explicit cache_control breakpoints; cache reads billed at a fraction of input |
|---|---|
| OpenAI prompt caching | Automatic for long prompts; cached tokens discounted |
| Gemini context caching | Implicit and explicit caches with a storage fee |
| vLLM / SGLang prefix caching | Same idea when self-hosting |
On AWS: Bedrock supports prompt caching on supported models with cache checkpoints in Converse.
How it fails
- A timestamp in the first line of the system prompt — 0% cache hits
- Reordering tools between requests
- Paying cache-write premiums on prefixes that are never reused
What the interviewer asks next
Why does order matter so much?
The cache matches a prefix token-for-token. The first differing token ends the match, and everything after it is processed — and billed — normally.
Prompt caching vs semantic caching?
Prompt caching reuses computation for an identical prefix and still generates a fresh answer. Semantic caching skips the model call entirely and returns a stored answer for a similar question.