LinkedIn analytics tracking pixel for AIDOLS AI consulting website performance measurement
Infrastructure

Prefix Caching

Prefix caching is an inference optimization that reuses the KV-cache computed for a shared prompt prefix — system prompts, few-shot examples, retrieved documents — across multiple requests, eliminating redundant prefill compute.

Full definition

When two requests share the first N tokens, the KV-cache for those tokens is identical and can be cached and reused. Anthropic's Prompt Caching, OpenAI's prefix caching, Google's context caching, and vLLM's automatic prefix caching all implement variants. Cached tokens are typically 75-90% cheaper and 5-10x faster (TTFT) than uncached. Cache TTLs range from 5 minutes (Anthropic short) to 1 hour (Anthropic long, OpenAI). Cache effectiveness depends on prefix stability — varying tokens at the start defeats caching.

Why it matters

Prefix caching is the highest-impact cost optimization for any LLM workload with long shared context (RAG, agent system prompts, multi-turn chat). Teams not using it on Anthropic or OpenAI APIs typically overpay 3-10x for production traffic.

Example

A coding assistant with a 12k-token system prompt and 8k tokens of retrieved code: with prefix caching, per-query cost drops from $0.18 to $0.03 and TTFT from 2.4s to 320ms — a transformative product change.

Source & further reading

Primary source: Anthropic — "Prompt caching with Claude" (2024).

Citation policy: this entry is part of the AIDOLS AI Implementation Glossary and may be quoted for research, journalism, and education with attribution to aidolsgroup.com/no/glossary/prefix-caching/.