Prefix Stability Is Everything
KV-cache prefix matching works strictly from token 0 forward. A single changing timestamp, random request ID, or dynamic user name at the top of your system prompt invalidates the entire cache for every turn.
Optimal Prompt Layout
Place unchanging instructions, schemas, tool definitions, and static reference documents first (>= 1,024 tokens). Append dynamic timestamps, retrieval snippets, and live user messages strictly at the end.
Core Physics Formula
Cached Session Cost = 1 * CacheWrite(Static) + (Turns - 1) * CacheRead(Static) + Turns * Input(Dynamic)