RTX 3050 - Order Now
Home / Blog / Tutorials / Prompt Caching Deep Dive
Tutorials

Prompt Caching Deep Dive

vLLM's prefix caching, semantic caching, hosted-API prompt caching — the layers and how they compound.

Table of Contents

  1. Layers
  2. Composition
  3. Setup
  4. Verdict

Caching for LLM workloads has multiple distinct layers. Each addresses different cache hit patterns. Understood and combined, they compound for substantial cost / latency savings. Standard production setup uses 2-3 layers.

TL;DR

Three caching layers: (1) vLLM prefix caching (KV cache reuse on shared prompt prefixes), (2) semantic caching (embed query, look up similar past), (3) literal response caching (exact prompt match). Layers compose: prefix cache helps similar-prefix queries; semantic cache helps near-paraphrase queries; literal cache helps exact-repeat queries.

Layers

  • vLLM prefix caching: KV cache for shared prompt prefixes (system prompt, RAG context). 2-5× TTFT win on cache hit. Free with --enable-prefix-caching.
  • Semantic caching: embed query; vector lookup; return cached response if similarity > threshold. ~20-40% hit rate typical.
  • Literal response caching: exact-match cache (Redis with prompt hash key). Highest hit rate on FAQ / repeat queries.
  • Hosted-API prompt caching (OpenAI / Anthropic): provider-side caching of system prompts; cost reduction on shared prefixes.

Composition

Standard production stack:

  1. Request arrives
  2. Literal cache lookup (Redis); if exact-match, return
  3. Semantic cache lookup (Qdrant + BGE); if similarity > 0.95, return
  4. vLLM serves: prefix caching reuses KV cache for shared parts of prompt
  5. Response returned + cached at literal + semantic layers

Net hit rate at all-layer composition: typically 40-60% for FAQ-style workloads, 20-30% for general chatbots. Each hit saves the full LLM call cost.

Setup

  • vLLM prefix caching: --enable-prefix-caching — default on in production
  • Semantic cache: BGE-large embeddings + Qdrant collection + 0.95 similarity threshold
  • Literal cache: Redis with SHA256(prompt) key + 24-hour TTL
  • Order matters: cheapest cache lookup first (literal > semantic > vLLM)

Verdict

Composed caching is one of the highest-ROI optimisations for production LLM workloads. Three layers; each cheap; together they capture 30-60% of requests at near-zero cost. Build day-one of production; the cost saving compounds with traffic growth.

Bottom line

Three layers; compose for 30-60% hit rate. See semantic cache.

Need a Dedicated GPU Server?

Deploy from RTX 3050 to RTX 5090. Full root access, NVMe storage, 1Gbps — UK datacenter.

Browse GPU Servers

gigagpu

We benchmark, deploy, and optimise GPU infrastructure for AI workloads. All data in our guides comes from real-world testing on our UK-based dedicated GPU servers.

Ready to deploy your AI workload?

Dedicated GPU servers from our UK datacenter. NVMe storage, 1Gbps networking, full root access.

Browse GPU Servers Contact Sales

Have a question? Need help?