Why it matters

Shared prompts common in production. Prefix caching cuts cost. Understanding shapes efficient serving.

Advertisement

The architecture

Identify common prefix.

Compute KV cache once; store.

New requests with same prefix reuse cache.

Prefix cachingDetect common prefixhash-basedCompute KV oncecache itReusefor matching requestsAutomatic prefix caching in vLLM v0.4+; explicit in SGLang RadixAttention
Prefix cache mechanism.
Advertisement

How it works end to end

vLLM automatic: detects prefixes via hash of tokens; reuses.

SGLang RadixAttention: tree structure of shared prefixes.

Cache eviction: LRU when memory tight.

Impact: 2-5x speedup for prefix-heavy workloads.