vLLM automatic prefix caching for chat and RAG workloads

Automatic prefix caching lets vLLM reuse computed attention state for shared prompt prefixes, which helps chat and RAG traffic that repeats the same context. It also creates a cross-tenant timing risk that cache salts and a measured configuration should address before go-live.

On this page

When vLLM automatic prefix caching pays off for chat and RAG

Keep prefix caching on for most chat and RAG servers, and switch it off only when a benchmark or a tenant isolation requirement says otherwise. Prefix caching lets vLLM reuse the attention work already computed for a leading run of tokens that matches an earlier request, so the prefill cost of that shared text is paid once instead of on every request. The savings are largest where the same long text opens many requests: a shared system prompt across all users, the growing conversation history in a multi-turn chat, or the same retrieved documents reused across questions in a RAG workflow. The flag is controlled by --enable-prefix-caching and its --no-enable-prefix-caching form, and the reader should confirm the default for the vLLM release they plan to run before relying on it.

The cost question is less about licensing than it looks. vLLM is licensed under Apache-2.0 and has no paid edition, so enabling the cache adds no software fee. What it changes is how much of your GPU capacity goes to repeated prefill, and that capacity, plus the engineers who tune and monitor the server, is where the money goes. A useful check is to replay a sample of real chat or RAG traffic with the cache on and off and compare time to first token and token throughput on your own hardware. Prefix reuse helps least when prompts are short, unique per user, or change at their start on every request, because a cache hit needs an exact match of leading tokens. Watch the KV cache metrics exposed on the /metrics endpoint to see whether the cache is being used as expected.

Prefix reuse depends on the content of the prompt, so the decision also depends on who shares the server. Cached blocks can be reused across requests, which raises a timing side channel risk between tenants: one party may infer whether another party's prompt shares a prefix by measuring response latency. The vLLM security guide covers this risk and describes per-tenant cache_salt values, which keep cache reuse inside a tenant boundary. Before enabling the cache on a shared server, confirm with your security team whether tenants must be isolated, decide how each application will pass a salt, and test that requests from different tenants do not reuse each other's cached blocks. For a single-tenant internal chat or RAG service, the risk is usually lower, but the reader should still record that decision.

Which prefix caching settings fit which workload

This table compares the prefix caching settings against the workload patterns where they matter, from shared system prompts to synthetic benchmark runs. Read each row as a starting point, then confirm the flag names and defaults against the stable engine arguments page for your vLLM version before you change anything in production.

Workload patternRecommended settingWhy it fitsWhat to confirm or watch
Shared system prompt across users--enable-prefix-caching, with cache salt only if tenants are separatedIdentical instruction prefixes can be reused across requests, which reduces repeated prefill work.Confirm the flag and default on the stable engine arguments page for your version.
Multi-turn chat with growing history--enable-prefix-cachingEach new turn resends earlier turns, so cached prefixes from the conversation can be reused.Cache capacity is shared with active requests, so watch KV cache use under load.
Repeated RAG documents--enable-prefix-caching when the same documents recur in promptsPopular retrieved passages placed at the same position in prompts can be reused across queries.Reuse depends on identical token sequences, so changes to chunking or ordering reduce hits.
Multi-tenant SaaS or shared endpoint--enable-prefix-caching with a per-tenant cache_salt valueThe salt keeps tenants' cached prefixes separate, which addresses cross-tenant timing risk.Confirm salt handling and the security guide guidance for your version before exposing the endpoint.
Synthetic benchmark runs--no-enable-prefix-cachingDisabling reuse keeps each request's prefill cost consistent for repeatable measurements.Re-enable for production tests so results reflect real prompt reuse.
Unique prompts with little shared textOften no measurable gain, so test both settingsWithout shared prefixes there is little to reuse, and caching adds bookkeeping.Measure time to first token with a representative dataset before deciding.

Which traffic patterns reuse prefixes well

Prefix caching only helps when the start of each request is identical to a request the server has already processed. The cards below cover the common workloads where that holds, what keeps the prefix stable, and the small edits that quietly break it.

Shared system prompts

Many applications send the same long system prompt, persona or policy text with every request. The prefix stays stable as long as the instructions come first and nothing per-user is inserted above them. A timestamp, request ID or user name placed at the top of the system prompt creates a new prefix on every call and removes the reuse. Check the rendered prompt in logs to confirm the shared portion is byte-identical across requests.

Engine arguments

Multi-turn chat history

Each new turn resends the earlier conversation, so the previous turns form the prefix of the next request. Reuse holds only if the chat template renders earlier turns the same way every time. Changes such as trimming old messages from the front, summarizing history or rewriting earlier assistant turns shift the start of the sequence and force recomputation. Confirm that the history your application sends is append-only in practice.

Repeated documents in RAG

RAG pipelines often send the same retrieved documents or a fixed knowledge block to many users. Reuse depends on the chunks appearing in the same order with the same text. Reordering retrieved chunks by score on each query changes the prefix even when the set of documents is identical. Placing the query after the stable document block, rather than before it, keeps the shared portion at the front of the prompt.

Agent loops with stable tool definitions

Agents resend the same tool schemas and instructions on every step of a loop, and each step appends the previous outputs. The tool definitions are the most reusable part of the request. Serialization drift breaks them: JSON keys emitted in a different order, a tool list rebuilt from an unordered set, or a per-run session ID inside a tool description. Pin the serialization and verify it with a test that compares two rendered requests.

Workloads that rarely repeat prefixes

Single-shot generation, unique user documents, and prompts built from fresh data each time seldom share a prefix with earlier traffic. For these workloads, enabling the cache adds bookkeeping without saving prefill work. Measure the hit rate from the metrics endpoint on representative traffic before deciding. If the rate stays low, leave the feature off and spend effort on batching or memory settings instead.

vLLM metrics

Why vLLM benchmark recipes switch prefix caching off

Several vLLM recipes set --no-enable-prefix-caching when they publish performance numbers, and teams copying those commands often assume the setting is a recommendation for production. It is not. The flag is a measurement choice: when a benchmark replays synthetic prompts, cache hits would make runs differ from one another in ways that have nothing to do with the model or hardware, so turning the cache off keeps comparisons consistent. The vLLM engine arguments documentation lists the --enable-prefix-caching and --no-enable-prefix-caching forms, and the Llama 4 Scout recipe shows the flag in a benchmarking context.

The risk is in carrying that benchmark result into a go-live decision. A recipe number measured with the cache disabled describes a server that never reuses a shared system prompt, a chat history or a repeated RAG document, which is the traffic where prefix caching usually matters most. Before deciding on the setting, build a benchmark dataset that reflects your real traffic, including the proportion of requests that share a prefix, and run it twice, once with --enable-prefix-caching and once without. Compare time to first token and throughput under the concurrency you expect, not only the peak numbers from a recipe.

Keep the production configuration as the one you benchmark. If you adopt the setting after testing, record the exact flags and the dataset used so later upgrades or model changes can be re-measured against the same workload. For the method itself, including dataset choice, matching concurrency and reading latency metrics, see the vLLM benchmarking guide and the benchmarking topic in this group.

How a request with a cached prefix moves through vLLM

The diagram starts with a client request that carries a tenant cache salt and enters the vLLM server inside a trust boundary around the shared GPU server. The engine looks up the prefix in the KV cache: a hit reuses cached blocks and skips recomputing that part of the prompt, while a miss computes the prefill and stores the new blocks. Check that the salt is set per tenant, so that a cache hit can only come from the same tenant's earlier requests, and that the response path carries no cache state between tenants.

Request path through the vLLM server for a prefix cache hit and miss.

Enabling and verifying prefix caching on a vLLM server

This sequence turns prefix caching on for a vLLM server, confirms the flag is active, and measures whether shared prefixes are being reused under traffic that resembles production. The result is a recorded baseline that shows whether the setting helps your chat or RAG workload before it goes live.

  1. Confirm the vLLM release and flag names

    The platform engineer checks which vLLM release is installed and reads the engine arguments page for that release to confirm the exact names of the prefix caching flags, including the enable and no-enable forms. Flag names and defaults can change between releases, so the reader should not copy a name from an older recipe or blog post. The step is done when the installed version and the flag names are written into the change record.

  2. Confirm the chat template for chat completions

    Before changing the server, the engineer confirms that the model either ships a chat template or will be started with a template supplied through the chat template option. Without a template, the chat completions endpoint will not serve requests, so a failure here can look like a caching problem. The step is done when a test call to the chat completions endpoint returns a normal response with no template error in the server log.

  3. Start the server with prefix caching enabled

    The platform engineer starts the server with vllm serve and sets the prefix caching flag confirmed in the first step, alongside the model, context limit and other settings already in the deployment plan. The engineer records the full command in version control so the same settings can be reproduced after restarts or upgrades. The step is done when the startup log shows prefix caching as enabled and the server reports ready.

  4. Send paired requests with a shared prefix

    The engineer sends two requests that share the same long system prompt or document, with only the final user message changed, and then repeats the pair several times. Using the same API surface as production, such as the chat completions endpoint, keeps the test representative. The step is done when the requests complete without errors and the engineer has a log of request timing for each pair. Results from a single pair are not enough to judge reuse.

  5. Check cache use on the metrics endpoint

    The engineer reads the Prometheus-format metrics served at /metrics and compares prefix cache query and hit counters, along with KV cache usage, before and after the paired requests. The metric names should be checked against the metrics documentation for the installed release. The step is done when the hit counters rise after the repeated prefix requests, and the engineer records the change. If the counters stay flat, the prefix is likely not matching exactly, so the request construction should be reviewed.

  6. Protect the metrics endpoint before sharing it

    Because the --api-key option does not cover the metrics path, the engineer confirms that /metrics is reachable only from the monitoring network or through a reverse proxy that does not expose it to tenants. Cache metrics can reveal traffic patterns, so this check belongs with the verification work. The step is done when a request to the metrics path from an unapproved network location is refused.

  7. Record a baseline with production-shaped traffic

    The performance owner replays a representative sample of production prompts, including real system prompt lengths, multi-turn histories and retrieved documents, and records latency, throughput and cache hit figures with the flag on and off. The comparison should use the same model, hardware and concurrency for both runs. The step is done when the baseline is stored with the server configuration, the traffic sample description and the measured results, so later tuning can be compared against it. Ask your team or partner to confirm the sample size and concurrency before the run.

The cross-tenant timing risk and how cache salts address it

Prefix caching makes one request's latency depend on what other requests have already cached. The cards below cover the timing side channel the vLLM security guide describes, how per-tenant cache salts narrow it, where the gateway must own that control, and what remains outside a cache salt's reach.

The timing side channel

A request that reuses a cached prefix finishes its prefill faster than one that does not. An attacker who controls a request can send a candidate prompt and measure time to first token to infer whether another user recently sent a similar prefix. The vLLM security guide documents this prefix-cache timing side channel. Test it on your own deployment by timing cold and warm requests with and without another tenant's traffic.

vLLM security guide

Per-tenant cache salts

The cache_salt value is mixed into the prefix cache keys, so identical prompts sent under different salts do not share cached blocks. Assign one salt per tenant, customer or isolation boundary. Confirm the exact request field name and behavior against the vLLM version you run, since the security guide is the reference for this control.

Salts set by the gateway

A salt only isolates tenants if the client cannot choose or change it. Have the trusted API gateway or backend derive the salt from the authenticated identity and strip any salt the client sends. If a client can pick its own salt, it can also pick another tenant's salt and probe that cache. Verify this with a test that sends a forged salt and checks that the cache hit pattern does not change.

Salt granularity and cache reuse

Each salt splits the cache, so a per-user salt gives the strongest separation but removes sharing of common system prompts across users. A per-tenant salt keeps reuse inside an organization while still isolating tenants. Decide the boundary with your security team, then measure hit rate under that boundary, because the throughput gain from prefix caching shrinks as the number of partitions grows.

Shared model weights and runtime

Cache salts do not separate anything inside the model process. Tenants still share the same weights, GPU memory, scheduler and the KV cache pool, so memory-level or noisy-neighbor effects remain. Model weights loaded from a shared checkpoint store also remain a shared asset. Plan separate deployments for tenants whose isolation requirements exceed a logical boundary.

Logs, metrics and retained data

A salt does not stop prompts from appearing in application logs, tracing tools or the cache metrics that vLLM exposes at its metrics endpoint. Review what your gateway, observability stack and any prompt logging record, and restrict who can read those stores. Confirm with your compliance team how long request data is retained outside vLLM.

vLLM metrics docs

What to confirm for prefix caching in your environment

Is automatic prefix caching on by default in my vLLM release?

Confirm the default for your exact release before you write any capacity or latency expectations, because the flag behavior is the first thing to verify. vLLM documents --enable-prefix-caching and a --no-enable-prefix-caching form, so read the engine arguments reference for the version you run and check the effective value in the server startup log. Do not assume the default carries over from a recipe, a blog post or an older release. Record the flag in your deployment manifest so the setting is explicit and reviewable.

Does my vLLM version support cache salts for tenant separation?

Confirm that the release you plan to run supports per-tenant cache_salt values before you serve more than one customer or security domain from the same engine. The vLLM security guide describes prefix-cache timing side channels and per-tenant salts, but support depends on the version and the API path you use, so test it against your build rather than relying on the docs alone. If the salt is not available or not enforced for your request path, plan tenant isolation at the deployment level instead, with separate engines per trust boundary.

How does prefix caching interact with chunked prefill in my setup?

Ask your engineers to confirm how the scheduler combines chunked prefill with cache hits in the release and configuration you deploy, then measure it. Cached blocks shorten the prefill work for a request, but chunked prefill changes how the remaining prompt tokens are batched alongside decode steps, so time to first token can move in either direction. Test with your real prompt lengths and concurrency, and record the settings for --enable-chunked-prefill and the batching limits next to the cache setting so results can be reproduced.

Does my parallelism layout change how cached prefixes are reused?

Confirm how tensor and pipeline parallel sizes, and any data parallel replicas, affect cache capacity and cache hit rates in your release. Each replica or engine process holds its own KV cache, so a load balancer that spreads one conversation across replicas can lose hits that a sticky routing policy would keep. Check the parallelism and scaling documentation for your version, then test routing behavior with a multi-turn workload before you size the fleet or set session affinity.

What happens to cached prefixes when GPU memory runs short?

Confirm the eviction policy and how it behaves when the KV cache fills, because cached prefixes compete with active requests for the same blocks. Under memory pressure, cached blocks that are not in use can be evicted, which turns expected hits into misses and can make latency less predictable for long system prompts or large documents. Watch the KV cache usage and prefix cache hit metrics exposed on the /metrics endpoint during a load test, and tune memory settings before assuming the cache will hold your working set.

Does my chat template keep earlier turns byte-identical so prefixes match?

Confirm that the chat template your model uses renders conversation history the same way on every request, because prefix caching only matches identical token sequences. Templates that insert timestamps, reorder system messages, strip reasoning blocks or add whitespace differences between turns break reuse even when the visible text is the same. Models must have a chat template, or one supplied with --chat-template, to serve the chat completions API, so test the rendered prompt for two consecutive turns and compare the token prefix before you rely on hits.

Can my team validate these settings without outside help?

Yes, if your engineers can run a controlled load test with a realistic conversation mix, read the server metrics and repeat the test after each change. The checks above need a staging copy of the production model, a replay set of prompts that reflects shared system prompts and multi-turn sessions, and a log of each configuration. Ask a partner for a fixed-scope validation only if your team lacks the time or the multi-tenant security review skills, and ask for the written test plan and acceptance criteria before work starts.

How DeployOpen scopes prefix caching work on vLLM

DeployOpen scopes prefix caching work as a fixed-scope engagement, with the written scope and deliverables agreed before any configuration changes are made. DeployOpen is a Chainscore Labs company. It plans, implements, hardens and supports self-hosted open-source platforms inside the client's own infrastructure, including their cloud accounts, data centers or air-gapped networks. For vLLM, the scope usually starts with the workloads that will share a server: which system prompts are fixed, how long multi-turn sessions run, and which documents are retrieved repeatedly. Those answers decide whether --enable-prefix-caching is worth turning on for each serving endpoint and what the acceptance measurements must show.

The written scope then covers four kinds of work. Configuration sets the server flags and confirms the vLLM version in use. Cache salt design defines how the cache_salt value is assigned per tenant, per user or per customer, and who owns that mapping in the client's application. Security review checks how the endpoints are exposed, which reaches the prefix cache timing risk discussed in the security guide. Measurement records hit behavior and latency before and after the change, so the client can compare the results with its own targets. The client should confirm which of these items are included, which stay with its own teams, and how the deliverables are handed over.

Ongoing support is available as a retainer after the initial work closes. Retainer coverage is worth discussing early, because vLLM ships new minor releases about every two weeks, and cache behavior, flags and metrics can change between versions. Ask the vendor to state in the quote how release tracking, upgrade testing and re-measurement are handled, and what is included in the one-time work compared with the recurring retainer.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.