Cache-Control header being overridden by Cloudflare

cache

#1

I’m running a pretty simple JSON API on Heroku, and I just put CloudFlare in front of it. Before my cache control header was:

Cache-Control: max-age=0, private, must-revalidate

Now from CloudFlare it’s:

Cache-Control: public, max-age=14400

This is not a static file, it’s a json endpoint, so this breaks my app. What am I missing?


#2

So I set a page rule that covers my whole site and enabled Origin Cache Control, and now it seems to work. I can’t believe the default behavior overrides your cache-control headers, is that really the case?


#3

Here’s a short article on origin cache headers, but it applies to Static Content, so I’m not sure if it applies to your request. I suppose checking the headers for cf-cache-status would be an indication the following article would apply.

This detailed article makes my eyes glaze over:


#4

Yep, I read both of those. As you mentioned the first is only about static content. The second implies that CF normally overrides the Cache-Control header, but I can’t find that explicitly stated anywhere.


#5

I’m not a cache header expert, so I’ve never experimented with this, but it sounds like Cloudflare picks the longer expiration time.

if the Cache-Control header on the response from the origin server is less than the TTL described in the “Browser Cache Expiration” setting

I mentioned cf-cache-status, but that’s for Edge Cache, not Browser Cache. And this is where I really lose track of how origin cache headers affect Cloudflare’s cache settings.


#6

if the Cache-Control header on the response from the origin server is less than the TTL described in the “Browser Cache Expiration” setting

Ah ok, that’s helpful. Thanks!


#7

Still seems like a really strange default though.


#8

This topic was automatically closed after 14 days. New replies are no longer allowed.