Prompt caching stores the model's computed key and value tensors for a repeated prompt prefix, so the next request that starts with the same tokens skips the expensive prefill. That is the same KV cache that makes single-request decoding tractable, extended across requests Firecrawl's prompt caching guide. The important consequence for a trim: attention is causal, so the key and value vectors for token 500 depend only on tokens 1 through 499. Change token 12 and every vector from position 12 forward comes out different, which is why the saved state is useless from that point.
Most providers implement lookup with a hash. On Anthropic you mark a block with cache_control, and the provider writes one cache entry keyed by a cumulative hash of everything up to and including that block the Claude platform docs. One sentence from those docs is worth memorizing: place the breakpoint on the last block that stays identical across requests, which for a static prefix and a varying suffix means the end of the prefix, not the varying block a walkthrough of cache invalidation.
The billing mechanics matter for pricing a reset later. Reads bill at a discount (roughly 0.1x base input on Anthropic's tiers, with some models lower), while writes carry a premium, 1.25x base input at the 5-minute lifetime and 2x at the 1-hour lifetime the Claude platform pricing table. Break-even on a 5-minute write is a little over one read, so a single subsequent request typically makes the write pay for itself Digital Applied's caching playbook.
OpenAI's side works the same way in principle but without manual markers unless you want them: caching turns on automatically for prompts of 1024 tokens or longer, works on exact prefix matches, and cached input bills at a 50% reduction on the models where it applies Humanloop's prompt caching overview. The vendor documentation is direct about ordering advice: put static content at the beginning and variable content at the end the OpenAI prompt caching guide.



