Prompt caching reuses a cached prefix instead of reprocessing it, but it only saves work when the cache is actually hit. Claude prompt caching reports cache usage in the response: cached content is read at a fraction of the base input price, while a cache write costs more than base input. The default cache lifetime is 5 minutes, refreshed each time the cached content is used. Measuring the hit rate, the share of input tokens served from cache, tells you whether the breakpoint is in the right place.
What you need
- An API that reports cache read and write tokens in usage
- A set of repeated requests with a shared prefix
- A cache breakpoint on the stable prefix
Step 1: Record cache read and write tokens per request
For each request, record the input tokens, the cache read tokens and the cache write tokens from the usage object. A request with no read tokens missed the cache entirely.
Step 2: Compute the hit rate across the requests
Divide the total cache read tokens by the total input tokens across the set. A high rate means most of the prompt was served from cache; a low rate means the prefix is being reprocessed every time.
Step 3: Move the breakpoint when the rate is low
If the rate is low, check the breakpoint: it must sit on the last block whose prefix is identical across requests. A breakpoint on a block that changes every request, such as one holding a timestamp, never hits, because the prefix hash changes each time.
Worked example: synthetic cache hit rate for 4 requests
The table below is a synthetic example. It shows the expected result of measuring cache hits; no API was called.
| Request | Input tokens | Cache read tokens |
|---|---|---|
| Request 1 | 10,000 | 0 – first write |
| Request 2 | 10,500 | 10,000 |
| Request 3 | 11,000 | 10,500 |
| Request 4 | 11,000 | 0 – breakpoint moved |
Expected result (UNTESTED). the hit rate is high for requests 2 and 3, but request 4 misses because the breakpoint moved. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- The default cache lifetime is 5 minutes, so a gap longer than that loses the entry unless a 1-hour duration is used.
- The lookback window is 20 blocks: a breakpoint more than 20 blocks past the last write will not find it.
- Cache reads cost a fraction of base input price, while cache writes cost more, so a write on every request with no reads is worse than no caching.
- Automatic caching places the breakpoint on the last cacheable block, which fails when that block changes every request.
