Prompt caching reuses a stable input prefix or a separately stored context object, depending on the provider. Keep shared instructions and approved reference material stable; place request-specific material after them when the API supports prefix reuse. Treat cache lifetime as a content decision. If a policy, tool permission, or tenant scope changes, the cached context must be replaced or allowed to expire. Do not place one customer's private data in a prefix reused across customers.
Prompt caching: reuse stable context with a versioned expiry
Decision in practice
A compliance assistant answers 260 daily questions against one approved procedure. The procedure and schema are versioned together as PC-14 and may be cached for the day's approved window. Each request adds only its case facts after the shared context. When legal staff publish PC-15, the application switches the cache key and stops accepting PC-14 answers for new cases. A private case note never enters the shared prefix. The team samples outputs before and after the switch to verify that the new exception is actually applied.
Cache identity: tenant scope + procedure PC-14 + schema v3.
Shared prefix: approved instruction and procedure only.
Per-request suffix: case facts and authorized user context.
Invalidate: new procedure, changed permission, expired retention window.Performance and operating cost
A cache can lower billed or processed input on repeated requests, but creation, storage, and expiry may have their own cost. Break-even depends on prefix size, reuse count, and provider billing rules; measure actual cache hits rather than assuming savings. A stale cache can produce systematic errors across many requests. Include cache identity in traces and evaluate a cache miss and hit path against the same cases. Context limits still apply even when the input is cached.
Common Mistakes
- Do not cache private data across tenant boundaries.
- Do not reuse an old policy prefix after a revision.
- Do not equate a configured cache with an observed hit.
Connected lessons
- Prompt Engineering
- Production prompt engineering
- Prompt budgets: trade output quality against cost and tail latency
- Prompt releases: version the whole decision path and keep a rollback
- Metamorphic tests: verify behavior when harmless details change
- Project: regression-test a customer triage prompt
- Advanced prompt engineering decisions
