Home » Prompt Caching: What Is Reused and What Still Occupies Context

Prompt Caching: What Is Reused and What Still Occupies Context

Two full context stacks retain a matching prefix and distinct tasks A and B; dotted paths reuse only prefix processing from a shared cache.

Prompt caching reuses eligible processing for a matching prompt prefix. It does not remove that prefix from the request's logical input, choose which documents are relevant, or create durable memory that an application can retrieve later. A cache hit and a larger context window solve different problems.

For an agent that repeatedly receives the same repository policy and a changing task, the useful design question is which input remains stable without becoming stale or losing its intended meaning.

Separate three kinds of reuse

Mechanism What the application is trying to reuse
Prompt caching Eligible processing associated with matching input
Retrieval Selected evidence from a larger collection
Durable memory Information intentionally retained for later tasks

Our context, retrieval, and memory guide explains the latter boundaries. A provider cache does not replace them: omitting a required policy from a later request is not the same as sending it through a supported cache mechanism.

Put stable content before changing content when the API permits it

An illustrative input layout is a stable instruction section, a versioned reference document, and then the current task. The exact roles and ordering must preserve the selected API's instruction semantics; moving an untrusted document into a higher-authority role to improve caching would change the application.

Anthropic's prompt-caching documentation describes prefix matching, cache breakpoints, and conditions that invalidate reuse. In its explicit-breakpoint design, changing content before the breakpoint changes the prefix identity. Eligibility, supported features, lifetimes, and accounting are implementation-specific and must be checked for the chosen model and platform.

A timestamp placed before the stable material can therefore be worth inspecting. So can tool definitions that the application rebuilds in a different order each time. Fix unnecessary variation only when the resulting request still expresses the intended contract.

Read usage fields without erasing cached input

For the documented Anthropic accounting, total input includes cache reads, cache creation, and uncached input. A constructed usage record might contain:

{"cache_read_input_tokens":5000,"cache_creation_input_tokens":0,"input_tokens":100}

Under that accounting, the total is 5,100 input tokens, not 100. These are illustrative numbers, not an API response obtained by Context Fault.

The provider's context-window documentation concerns the input and output capacity of a request. A discounted or reused input segment should not be treated as permission to exceed the relevant capacity or ignore the space needed by a response and tool interaction.

Do not transfer one provider's field meanings into another provider's billing or limit model. Read the actual response schema and record the API version with an evaluation.

Keep freshness ahead of hit rate

Suppose the cached reference includes the supported database version. A repository upgrade changes that fact. Preserving the old prefix merely to keep a hit would present obsolete guidance to the agent.

Version stable material and change it when the owning source changes. The resulting miss may be the correct outcome. A cache is allowed to optimize a valid input; it should not become the reason the input remains wrong.

Similarly, do not append every historical task to retain an expanding shared prefix. Inspect whether that history remains useful and authorized. More reusable text can still bury the task's evidence or retain material the new caller should not receive.

Evaluate a concrete request family

Before claiming a benefit, preserve comparable requests, eligible-prefix sizes, creation and read usage, response latency, output validity, and the chosen pricing terms. Include misses and expired entries. A fast second request does not, by itself, isolate caching from other sources of variation.

Keep correctness checks the same when comparing layouts. If a cheaper request omits an essential instruction, it is a different task rather than a successful optimization.

No provider API, latency comparison, or cost experiment was run for this article. The outcome proposed is a request layout whose stable portion is justified by the task, whose changing portion is explicit, and whose reuse can be measured using the actual provider contract.

You may also like