# How should I set kv cache in vllm?

**URL:** <https://discuss.vllm.ai/t/how-should-i-set-kv-cache-in-vllm/1947>\
**Category:** General\
**Created:** [November 18, 2025, 8:10am UTC](https://discuss.vllm.ai/t/how-should-i-set-kv-cache-in-vllm/1947 "2025-11-18T08:10:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Septemberlemon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.vllm.ai/septemberlemon/32/915_2.png) [@Septemberlemon](https://discuss.vllm.ai/u/Septemberlemon)\
**Post date:** [November 18, 2025, 8:10am UTC](https://discuss.vllm.ai/t/how-should-i-set-kv-cache-in-vllm/1947/1 "2025-11-18T08:10:26Z")

</div>

I noticed that client includes the entire dialogue history with each request in a long conversation, did vllm set the kv cache itself?  
How does it identify the different conversations during parallel processing?

---

<div class="post-metadata">

**Author:** ![RunLLM](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.vllm.ai/runllm/32/233_2.png) [@RunLLM](https://discuss.vllm.ai/u/RunLLM)\
**Post date:** [November 18, 2025, 8:10am UTC](https://discuss.vllm.ai/t/how-should-i-set-kv-cache-in-vllm/1947/2 "2025-11-18T08:10:58Z")

</div>

vLLM does not automatically maintain or identify conversation history; the client is responsible for including the full dialogue history in each request. vLLM uses Automatic Prefix Caching (APC) to cache and reuse the KV cache for shared prefixes across requests, but it does not track conversations or user sessions itself. Each request is treated independently, and KV cache reuse is based solely on matching token prefixes, not on conversation IDs or user metadata. Thus, different conversations are not explicitly identified by vLLM during parallel processing—cache hits occur only when the token sequences match exactly in the prefix portion of the prompt, regardless of which conversation or user sent the request. For multi-turn chat, the client must concatenate the full history into the prompt for each turn, and vLLM will cache/reuse any shared prefix portions as possible based on token matching, not conversation context or user ID.

For more details, see [this discussion](https://github.com/vllm-project/vllm/issues/2766) and [the documentation on Automatic Prefix Caching](https://docs.vllm.ai/en/latest/features/automatic_prefix_caching/).

Would you like more detail on how APC works or how to optimize cache reuse in multi-turn chat?

Sources:

- [https://github.com/vllm-project/vllm/issues/2766](https://github.com/vllm-project/vllm/issues/2766)
- [https://docs.vllm.ai/en/latest/features/automatic\_prefix\_caching/](https://docs.vllm.ai/en/latest/features/automatic_prefix_caching/)

Hint: Mention @RunLLM in the post for followups.

---

<div class="post-metadata">

**Author:** ![Septemberlemon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.vllm.ai/septemberlemon/32/915_2.png) [@Septemberlemon](https://discuss.vllm.ai/u/Septemberlemon)\
**Post date:** [November 18, 2025, 8:27am UTC](https://discuss.vllm.ai/t/how-should-i-set-kv-cache-in-vllm/1947/3 "2025-11-18T08:27:33Z")

</div>

@RunLLM how many prefix will apc cache? it there a length limit?

---

<div class="post-metadata">

**Author:** ![RunLLM](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.vllm.ai/runllm/32/233_2.png) [@RunLLM](https://discuss.vllm.ai/u/RunLLM)\
**Post date:** [November 18, 2025, 8:27am UTC](https://discuss.vllm.ai/t/how-should-i-set-kv-cache-in-vllm/1947/4 "2025-11-18T08:27:51Z")

</div>

APC in vLLM caches as many prefixes as can fit in the available KV cache GPU memory; there is no fixed limit on the number of prefixes, but the total is constrained by the size of the KV cache buffer. When the cache is full, vLLM evicts the least recently used (LRU) blocks to make space for new prefixes. There is no explicit length limit for a single prefix, but very long prefixes will consume more cache blocks, reducing the total number of unique prefixes that can be cached simultaneously. See [design docs](https://docs.vllm.ai/en/latest/design/prefix_caching/) and [APC docs](https://docs.vllm.ai/en/latest/features/automatic_prefix_caching/).

Would you like more detail on how cache eviction or block sizing works?

Sources:

- [design docs](https://docs.vllm.ai/en/latest/design/prefix_caching/)
- [APC docs](https://docs.vllm.ai/en/latest/features/automatic_prefix_caching/)

Hint: Mention @RunLLM in the post for followups.
