Prefix changes on every request
Detect: Reported cache reuse remains low despite repeated tasks.
Recover: Remove unnecessary volatile fields from the reusable prefix.
Reuse provider-supported computation for stable prompt prefixes while preserving fresh generation and provider-specific eligibility, retention, and billing rules.
Context caching, often called prompt or prefix caching, reuses intermediate computation for an eligible repeated prefix. The provider still generates a new response for the request. It differs from semantic caching, which returns a previously generated answer for a similar question, and from durable agent memory, which stores application state.
OpenAI and Anthropic expose provider- and model-specific caching behavior. Eligibility thresholds, prefix matching, controls, retention, routing, and usage accounting can differ and change over time. OpenAI documents model-dependent cache controls and reporting; Anthropic documents explicit and automatic caching options with cache-control semantics. Verify the exact model and deployment documentation instead of assuming one provider’s parameters or lifetime apply to another.
A prototype repeats identical stable prefixes and confirms reuse through reported usage rather than latency alone.
Production uses deterministic prompt serialization, separates stable from changing segments, and records cache read, write, and miss behavior.
Enterprise scale evaluates retention and data policies, request locality, template-version churn, and net economics including any cache-write charges.
Serializes reusable instructions, tool definitions, and approved reference material consistently.
Applies the supported model-specific controls without pretending all providers share one API.
Appends changing user data and current task evidence after reusable segments where appropriate.
Records provider-reported cached usage and relevant billing categories.
Tracks reuse, prefix changes, retention behavior, and total accepted-task cost.
flowchart LR
S["Stable instructions and tools"] --> P["Deterministic prefix"]
P --> C["Provider cache eligibility and lookup"]
U["Current user task and evidence"] --> D["Dynamic suffix"]
C --> M["Fresh model generation"]
D --> M
M --> A["Validated new answer"]
M --> R["Cache usage and cost records"]Verify supported model, prefix requirements, controls, and applicable data-retention policy.
Separate stable instructions and schemas from timestamps, user-specific facts, and changing retrieval.
Keep segment order and bytes stable where the provider requires matching prefixes.
Use the provider’s documented caching mechanism and version the adapter configuration.
Send the dynamic suffix and treat the output as a new generation requiring normal validation.
Inspect reported usage and compare net cost and latency with a no-reuse baseline.
Enterprise analytics · Illustrative enterprise scenario, not a reported customer outcome.
An analytics assistant uses a large approved schema description across many separate questions.
The same schema instructions are repeatedly processed, but timestamps inserted near the beginning prevent prefix reuse.
Reduce repeated prefill work while keeping each query’s data and answer current.
A deterministic prefix contains the versioned schema and tool definitions; current task data appears in a separate suffix.
When the schema changes, the prefix version changes intentionally; correctness takes priority over retaining the previous cache hit rate.
Measure cached-token share, write and read cost, time to first output, and template churn; a warm prefix is an optimization, not an availability guarantee.
| Decision | Benefit | Cost |
|---|---|---|
| Stable large prefixes | Can reduce repeated prefill work. | May retain unnecessary context if optimized without task relevance. |
| Longer supported retention | Can improve reuse across wider intervals. | May change cost and data-policy implications. |
| Provider abstraction | Centralizes usage and configuration handling. | Must preserve real capability differences instead of hiding them. |
Detect: Reported cache reuse remains low despite repeated tasks.
Recover: Remove unnecessary volatile fields from the reusable prefix.
Detect: Expected hits become misses under the selected model.
Recover: Verify current retention semantics and size capacity for misses.
Keep normal generation and output validation.
Use explicit provider-specific adapters.
Inspect documented usage fields and reconcile cost.