Local LLM Prompt Caching: Reuse Explained (October 2026)

How llama.cpp, vLLM and LM Studio decide whether to reuse your prompt's KV cache, what each reports about tokens saved, and where the reuse stops.

Updated November 1, 2026

Every request that re-sends a long prompt makes the runner recompute work it has already done, unless the runner recognises the identical prefix and reuses what it computed last time. Prompt caching is the mechanism for that, and llama.cpp, vLLM and LM Studio each document a version of it. What differs is how it is switched on, what it reports back, and how much it costs you in memory.

What prompt caching actually saves

The unit that gets reused is the KV cache: the key and value vectors computed for every token read, for every layer, for every key-value head. Its size is fixed by the architecture and the context length, which is why the VRAM arithmetic page is about memory, not time.

Reuse does not shrink that cache. It avoids recomputing it. If a 20,000-token system prompt arrives again with 300 new tokens appended, an uncached runner processes 20,300 tokens of prompt; a caching runner processes 300. The saving lands in prompt-processing time, not in VRAM.

Two settings look alike and solve opposite problems. Reuse buys you time. Cache quantization buys you memory. The llama.cpp server takes f32, f16, bf16, q8_0, q4_0, q4_1, iq4_nl, q5_0 and q5_1 for both the key and the value cache through -ctk/--cache-type-k and -ctv/--cache-type-v, defaulting to f16 on both. Ollama exposes the same trade in its FAQ, where OLLAMA_KV_CACHE_TYPE defaults to f16 and quantized K/V cache applies when Flash Attention is enabled, with q8_0 described as using “approximately 1/2 the memory of f16 with a very small loss in precision” and q4_0 as “approximately 1/4 the memory of f16 with a small-medium loss in precision”.

What each runner does

RunnerCache-reuse controlDefaultReports reuse per requestNotes
llama.cpp llama-server--cache-prompt / --no-cache-prompt, plus --cache-reuse N--cache-prompt enabled, --cache-reuse 0Yes: tokens_cached in the response--cache-reuse needs a chunk size; without it the KV shift pass is off
OllamaNot exposed as a per-request control in its documentationNot statedNot stated in the FAQ or context-length pagesDocs cover context length and KV cache dtype, not the reuse mechanism
vLLMenable_prefix_caching (CLI --enable-prefix-caching / --disable-prefix-caching)True in current vllm/config/cache.pyNot stated on the docs pageDocs say to set it; the current source default is already on
LM Studio (llama.cpp engine)Not exposed; controlled through load configNot statedNot statedoffload_kv_cache_to_gpu and flash_attention are engine-scoped
LM Studio (MLX engine)Automatic KV cache checkpointing (mlx-engine v1.8.5)AutomaticNot documented per request; cached prompt-token counts appear in the vendor’s own benchmarkDisk-backed, lives only while the model is loaded

Two rows deserve reading closely.

On llama.cpp, prompt caching is the server flag --cache-prompt, documented as “whether to enable prompt caching (default: enabled)”, and the /completion documentation says that “if cache_prompt is true, the prompt is compared to the previous completion and only the “unseen” suffix is evaluated.” The separate --cache-reuse N flag is what makes non-identical prefixes partially reusable: it is described as the “min chunk size to attempt reusing from the cache via KV shifting, requires prompt caching to be enabled”, and it defaults to 0, so the shift pass is off unless you raise it. The server also returns a tokens_cached value, defined as the “Number of tokens from the prompt which could be re-used from previous completion”, alongside tokens_evaluated, the “Number of tokens evaluated in total from the prompt”. That pair is the number to watch.

On vLLM, the documentation page states “Automatic Prefix Caching (APC in short) caches the KV cache of existing queries” and instructs you to “Set enable_prefix_caching=True in vLLM engine to enable APC”. The current source disagrees about the starting point: vllm/config/cache.py declares enable_prefix_caching: bool = True. In other words, on current vLLM the feature is already on unless you pass --disable-prefix-caching, and the docs page describes the older opt-in posture. Treat the source file as the current truth and the docs page as stale on this one point. For hybrid Mamba models, the same page documents a --prefix-match-unit setting that “sets the granularity at which prefix-cache keys are computed” and says “64 is a reasonable starting point”. It is also explicit about the limit: APC “only reduces the time of processing the queries (the prefilling phase) and does not reduce the time of generating new tokens (the decoding phase)”, so it buys little for a long generated answer.

Ollama is the honest gap in this table. Its documentation covers default context length by VRAM band and KV cache data type, but neither the FAQ nor the context-length page describes how prompt caching works or reports cached token counts. Rather than infer behaviour from silence, this page states what was searched: https://docs.ollama.com/faq and https://docs.ollama.com/context-length, both read on 2026-10-23 and again on 2026-11-01.

LM Studio splits by engine. Its REST load API exposes context_length, described as the “Maximum number of tokens that the model will consider”, plus offload_kv_cache_to_gpu (“Whether KV cache is offloaded to GPU memory. If false, KV cache is stored in CPU memory/RAM”) and flash_attention. Both of the last two carry the same restriction in the documentation: “Will only have an effect on LLMs and decision models loaded by LM Studio’s llama.cpp-based engine.” On Apple Silicon the MLX engine does something different again. Writing in LM Studio’s blog, Neil Mehta describes mlx-engine v1.8.5, which “saves KV cache records at fixed 256-token boundaries, then restores the longest available cached prefix”, so “By saving and restoring prompt cache to disk, the KV cache for follow-up requests does not need to be recomputed.” That store is temporary: it uses one scratch file under /tmp, and the metadata lasts only while the model stays loaded.

How to tell whether reuse is happening

Start with the number, not the intuition. On llama.cpp, read tokens_cached from the completion response and compare it with tokens_evaluated. A run where tokens_cached stays near zero is re-processing the whole prompt every turn, which is the normal outcome when something early in the prompt changes between requests.

Audit what sits at the front of the prompt. Reuse only survives an identical prefix. A timestamp, a session ID, a retrieved-document block or a per-request system prompt all sit near the front and destroy the shared span. Stable material belongs first, per-request material last.

The memory side, measured

Cache reuse does not free memory, so the ceiling still comes from the KV cache arithmetic. Taking Qwen/Qwen3-8B as the worked example: the model API reports an apache-2.0 licence, gated: false, and 8,190,735,360 safetensors parameters, last modified 2025-07-26. Its config.json gives 36 hidden layers, 8 key-value heads and head_dim 128. At f16, that is 2 x 36 x 8 x 128 x 2 = 147,456 bytes (about 147 KB, or 144 KiB) of cache per token.

Context lengthKV cache at f16Same at q8_0 (roughly half, per the Ollama FAQ)
4,096 tokens576 MiB (604 MB)about 288 MiB
32,768 tokens4.5 GiB (4.83 GB)about 2.25 GiB
131,072 tokens18 GiB (19.3 GB)about 9 GiB

This is why the default matters more than the reuse setting. Ollama’s context-length documentation states that “Ollama defaults to the following context lengths based on VRAM”, giving 4k below 24 GiB, 32k between 24 and 48 GiB, and 256k at 48 GiB or above. Raising the ceiling is what costs you the memory; caching is what stops you paying to re-read it. The context-window comparison covers which models reach which lengths, and the runner comparison covers which engine to pick for the hardware.

Where the catch is

Three catches. Ollama’s OLLAMA_KV_CACHE_TYPE is a global setting, so it applies to every model the server hosts rather than per model. llama.cpp’s unified KV buffer, on by default when the slot count is automatic, shares one pool across every sequence, so reuse and concurrent capacity compete for the same memory; --parallel sets the slot count and --cache-ram (default 8192 MiB) caps the prompt cache held in RAM. And LM Studio’s KV cache settings silently do nothing outside its llama.cpp-based engine, which reads as a bug in the MLX path when it is a documented scope limit.

Bottom line

Prompt caching is not a feature you shop for. On current vLLM it is already on, on llama.cpp the prompt-cache switch is already on and the more useful KV-shift pass needs --cache-reuse raised from its default of zero, and LM Studio’s MLX engine does it unasked. The practical work is verifying it: read tokens_cached, keep the shared prefix stable, and remember that reuse buys latency while KV cache quantization buys memory. Two problems, two knobs.