Prompt Caching Strategies
Overview
Prompt caching strategies are a set of techniques that allow the reuse of processing results for unchanging parts of a prompt between requests. This reduces the time to the first token and the cost of inference for scenarios with repeated system messages, instructions, or large contexts.
Key Strategies
| Strategy | Description | Use Cases |
|---|---|---|
| Prefix Caching | Caching KV-states for common prefixes | Multi-turn dialogues, system prompts |
| Semantic Caching | Caching responses to semantically similar requests | Repeated user questions |
| Context Caching | Caching the entire context between requests | Long sessions, document work |
Implementation
- API providers (OpenAI, Anthropic) offer automatic prefix caching.
- Standalone inference servers (vLLM) support prefix caching.
- Semantic caching uses vector databases to find similar queries.