Asked about Managing the context as it grows

How does prompt caching interact with context management?

An answer that works

Caching matches a stable prefix, so anything volatile must go last. If a summary is inserted near the front, it invalidates the cache every time it updates. Order from most stable to most volatile and the cache keeps working.

Reading an answer is not being able to give one. The section that teaches this is Managing the context as it grows, 4 hours of The agent loop.

Learn this properly