vLLM Automatic Prefix Caching logo

vLLM Automatic Prefix Caching

Free

KV-cache

FreeFree tier
Type
Open Source

About vLLM Automatic Prefix Caching

Automatic Prefix Caching (APC) is a feature in vLLM that caches the KV cache of previously processed queries. When a new query shares a common prefix with an existing cached query, the KV cache for that prefix is reused, eliminating the need to recompute the attention for the shared portion. This reduces latency and computational overhead, especially in workloads with repeated prefixes such as multi-turn conversations or long document processing. APC can be enabled by setting enable_prefix_caching=True in the vLLM engine configuration.

Key Features

Caches KV cache of existing queries for prefix reuse
Skips computation of shared prefix between queries
Simple activation via enable_prefix_caching=True in vLLM engine
Reduces latency for queries with repeated prefixes

Pros & Cons

Pros
  • Reduces computational cost for shared prefix regions
  • Decreases inference latency for frequent prefixes
  • Easy to enable with a single configuration flag
Cons
  • Increases memory usage due to storing additional KV cache entries
  • May not provide performance benefit when queries have little or no prefix overlap

Best For

Multi-turn conversations with repeated contextDocument processing with overlapping prefixesLong-form text generation with common starting tokensEnvironments with high query prefix overlap

FAQ

What is Automatic Prefix Caching in vLLM?
It is a feature that caches the KV cache of previously processed queries. When a new query shares the same prefix as an existing one, the cached KV cache is reused, avoiding recomputation of the shared part.
How do I enable Automatic Prefix Caching?
Set enable_prefix_caching=True in the vLLM engine configuration.
Which workloads benefit most from APC?
Workloads where many queries share common prefixes, such as multi-turn conversations or processing long documents with repeated context.