Skip to content
Book a call

Your CDN can serve a policy you have already changed

· 3-minute read · Engineering · by Direct Softworks

We shipped a crawler policy, watched the deploy succeed, and production kept answering with the old file for 26 minutes. The cache header was ours, and it was set to a day.

The deploy was green. The origin was correct. curl on the public URL returned the previous version, repeatedly, for almost half an hour.

cf-cache-status: HIT
Age: 1552

Twenty six minutes of the old policy, being served to everyone, after the change had shipped. And the reason was a header we had written ourselves the day before, with a comment explaining why it was a good idea.

The header

Cache-Control: public, max-age=86400

A day. The comment beside it said this was "short enough that a policy change lands the day it ships", which is a sentence that is true for a browser and exactly backwards behind a CDN.

Cloudflare, like every edge cache, obeys that header. A day does not mean crawlers refetch daily. It means the edge keeps serving the old file for up to a day after the origin changes. The deploy had worked perfectly and changed nothing that anyone could see.

Two caches, one header, opposite audiences

The thing that makes this confusing is that one directive is being read by two different systems for two different purposes.

The edge cache decides how long the CDN serves a stored copy without asking the origin. This is the one that determines whether your deploy is visible.

The browser cache decides how long a visitor's browser reuses its copy. This is the one people are thinking about when they set the number.

They are configured by the same header and they have completely different consequences, and it is entirely possible to reason correctly about the second while breaking the first.

The part that made it worse

When we lowered the value to 300 seconds and deployed, the response header still said something else entirely:

Cache-Control: public, max-age=14400

Four hours. Neither the old value nor the new one.

The zone had browser_cache_ttl: 14400 set, which makes Cloudflare rewrite the outgoing Cache-Control regardless of what the origin sends. So the number in our repository would never appear in a response, ever, and anybody tuning it by watching the response header would conclude their change had no effect and go looking for a bug that does not exist.

The origin header still governs the edge TTL. It just never reaches a client.

How to actually verify it

Not by reading the response header, which is now known to lie. By watching the cache status across a TTL boundary, on a fresh cache key:

U="https://example.com/robots.txt?probe=$RANDOM"
curl -sI "$U" | grep cf-cache-status     # MISS
sleep 3
curl -sI "$U" | grep -E 'cf-cache-status|age'   # HIT, Age: 3
sleep 330
curl -sI "$U" | grep cf-cache-status     # EXPIRED  -> the TTL really is 300

That is the only trustworthy test, and it takes six minutes. EXPIRED on the third call proves the edge is honouring the new value.

What to take from it

A small file that changes rarely should not be edge-cached for long. robots.txt is under a kilobyte and fetched a handful of times a day. There was never anything to save by caching it, and the cost of doing so was that a policy change was invisible until purged by hand.

Know which layer each number governs. Write it in the comment. Our replacement comment says explicitly that the value reaches the edge and never reaches a client, and tells the next person to verify with cf-cache-status rather than the header.

Purge after any deploy that changes a cached file. One API call. If you find yourself doing it often, the TTL is wrong.

Suspect the cache early. The diagnostic instinct that would have saved twenty six minutes is the same one from checking the shipped bundle rather than the server: when the thing you deployed is correct and the thing the world sees is not, stop investigating the deploy and start asking who is between you and the visitor.

More notes