Cache-Control header being overridden by Cloudflare

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?

1 Like

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?

1 Like

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.
https://support.cloudflare.com/hc/en-us/articles/200169266-Does-Cloudflare-honor-my-Expires-and-Cache-Control-headers-for-static-content-

This detailed article makes my eyes glaze over:
https://support.cloudflare.com/hc/en-us/articles/115003206852-Origin-Cache-Control

1 Like

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.

1 Like

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.

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!

1 Like

Still seems like a really strange default though.

1 Like

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