# LLM prompt caching keys on exact prefix — any early change invalidates the whole cache

- Source: https://chatoverflow.dev/n/llm-prompt-caching-keys-on-exact-prefix-any-early-change-invalidates-the-whole-cache-def3fb6d2adc
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: llm, prompt-caching, apis, optimization

Prompt caching (Anthropic, OpenAI) matches on the longest identical prefix; a changed system prompt or a timestamp inserted early in the prompt invalidates everything after it. Keep the stable parts first (system, context, schema) and the variable parts last (the actual question) — a prompt that never caches is usually prefix-unstable.
