Claude Certification Guides
CCAR-P/Domain 210 min read

Lesson 2.5

Prompt Caching Strategy at Scale

The mechanics of prompt caching, how to design request assembly so that a fleet of services shares cache hits, and how to diagnose the silent invalidators that make hit rates collapse.

Prompt caching is the highest-leverage cost and latency optimisation available on the Claude platform, and the one most often left underperforming. Caching is simple in principle (reuse a processed prefix) and unforgiving in practice (one changed byte and the reuse is gone). At scale, cache behaviour is a property of your architecture, not of any one prompt.

Mechanics

  • Caching works on the prefix of the request as rendered: tools first, then the system prompt, then messages in order.
  • You mark cache breakpoints with cache_control of type ephemeral on content blocks; up to four per request. A top-level cache_control on the request can also cache the last cacheable block automatically.
  • A cached prefix is matched exactly. Any change anywhere before a breakpoint invalidates that breakpoint and everything after it.
  • Minimum cacheable length depends on the model; shorter prefixes silently do not cache.
  • The default time to live is short (minutes) and refreshed on each hit; a longer TTL option exists at a higher write cost for prefixes reused less frequently.
  • Writes cost more than normal input tokens; reads cost a fraction. The usage object reports cache_creation_input_tokens and cache_read_input_tokens.
  • Caches are scoped to your organisation and to the model. Switching model forfeits the cache.

Current multipliers, minimums and TTL options are in the Anthropic docs; design to the principles.

Layered breakpoints

Think of the request as layers from most to least stable, and place a breakpoint at the end of each layer that is reused:

[ tools + system instructions ]        <- breakpoint 1: shared by all traffic on the route
[ reference corpus / policy docs ]     <- breakpoint 2: shared by a tenant or a product
[ conversation history so far ]        <- breakpoint 3: moves forward each turn
[ current user turn ]                  <- never cached

In a multi-turn conversation, move the history breakpoint to the latest assistant turn on each request. The previous breakpoint's cache serves the read; the new one is written. This pattern turns an agent loop's quadratic token growth into something close to linear cost.

Designing for a fleet

Hit rates collapse when several services or instances assemble "the same" prompt slightly differently. Centralise prompt assembly in the gateway and enforce:

RuleWhy
Identical tool definitions in identical orderTools are the first thing rendered; any difference invalidates everything
Byte-identical system prompt per route and versionWhitespace, a reordered sentence or a rendering difference breaks the match
No volatile values in the stable prefixTimestamps, request IDs, user names, session IDs, random example selection
Deterministic JSON serialisationUnsorted keys render differently between calls
Same model and same thinking configuration across the routeBoth are part of the cache identity or affect rendering
Volatile content after the last breakpointKeep the current turn, user context and dynamic data at the end

A frequent and expensive bug is a "last updated" or "today's date" line in the system prompt. If the model needs the date, pass it in the user turn.

Multi-tenant designs

Tenants should share as much prefix as possible. Put tenant-independent instructions and tools first with a breakpoint, then tenant-specific documents with a second breakpoint, then the conversation. The shared layer is written once for everyone; the tenant layer is written once per tenant and read many times. Never put tenant identifiers into the shared layer.

Operator changes without invalidation

Changing the system prompt mid-conversation to inject an instruction invalidates the cached conversation. On models that support system-role messages inside the messages array, append the instruction there: the prefix is preserved and the instruction carries operator authority. Where unsupported, append it to the next user turn rather than editing earlier content.

Measuring and diagnosing

Instrument every route with cache hit rate (cache read tokens divided by total input tokens) and alert when it drops. A zero read count on a route with repeated traffic always means an invalidator, never "caching is off for this model". Diagnosis checklist:

  1. Diff two consecutive requests byte for byte up to the breakpoint.
  2. Check tool order and tool description text between service instances.
  3. Look for interpolated time, IDs or randomness.
  4. Confirm the prefix exceeds the model's minimum cacheable length.
  5. Confirm the TTL has not expired between calls; infrequent traffic may need the longer TTL.
  6. Confirm model and thinking settings have not changed between calls.

Where available, cache diagnostics features can report why a request missed; check the docs for current support.

Warming and TTL strategy

For routes with bursty traffic, a scheduled request that touches the prefix keeps it warm; some designs do this with a minimal-output request. For prefixes reused every few minutes the default TTL is enough; for hourly reuse the longer TTL may be cheaper despite the higher write cost. Model it: write cost multiplied by writes per hour versus the savings on reads.

Exam focus

  • Caching is a prefix match over tools, system and messages in that order; a change before a breakpoint invalidates it and everything after.
  • Up to four breakpoints; layer them from most to least stable and move the history breakpoint forward each turn.
  • Volatile content (dates, IDs, user data) belongs after the last breakpoint; tool order and serialisation must be deterministic.
  • Verify with cache_read_input_tokens; zero reads on repeated traffic means a silent invalidator.
  • Caches are scoped by organisation and model; multi-model designs and mid-conversation system prompt edits forfeit reuse.
  • TTL choice is a cost model: default for frequent reuse, longer TTL for infrequent reuse with higher write cost.

Check yourself

5 questions

  1. 1.An architect reviews a request builder for a high-traffic assistant. The system prompt starts with the user's name and the current date, followed by 10,000 tokens of static policy text, with a cache breakpoint on the last system block. Cache reads are near zero. Which principle explains the problem?

  2. 2.A B2B assistant has a 20,000-token shared prefix. Users typically reply every 15 to 30 minutes during a working session. The team uses the default cache time to live and sees frequent cache misses. Which caching adjustment is MOST appropriate, and what is the trade-off?

  3. 3.A multi-tenant SaaS assistant builds its system prompt as: tenant name and tenant-specific policy (about 500 tokens), followed by 15,000 tokens of shared product instructions, followed by the tool definitions. Cache hit rates are poor because each tenant has a distinct prefix. Which restructuring MOST improves cache reuse across tenants?

  4. 4.A team added cache markers to a stable 8,000-token system prompt and confirmed, in a test script, that the second request reported cache-read tokens. In production, cache-read tokens are almost always zero while cache-creation tokens are reported on nearly every request. The system prompt text is identical in both environments. What is the MOST likely cause?

  5. 5.A retrieval-augmented service uses top-level automatic caching. Each request consists of a 6,000-token fixed instruction block followed by freshly retrieved passages and the user's question, which differ on every request. Usage data shows cache-creation tokens on every request and cache-read tokens that never cover more than the instruction block. The bill is higher than before caching was enabled. What is the MOST likely cause and fix?