Can't get caching working with Cache-Control:public

My origin server generates dynamic content but sends Cache-Control: public headers if it’s publicly cachable. I can’t persuade Cloudflare to cache this despite trying multiple page-rule variations of Cache Level: Cache Everything / Origin Cache Control: On .

For example:

$ curl -I http://mydomain.com/feed.rss
HTTP/1.1 200 OK
Date: Fri, 17 Jul 2020 14:18:10 GMT
Content-Type: application/rss+xml; charset=utf-8
Connection: keep-alive
Set-Cookie: __cfduid=d5eba866b85636e98366d611876b709812309812; expires=Sun, 16-Aug-20 14:18:10 GMT; path=/; domain=.mydomain.com; HttpOnly; SameSite=Lax
Vary: Accept-Encoding
Cache-Control: max-age=900, public
X-Request-Id: f33b44eb-46b1-4799-8497-54e2b62980af
X-Download-Options: noopen
X-XSS-Protection: 1; mode=block
X-Runtime: 0.109933
X-Permitted-Cross-Domain-Policies: none
X-Content-Type-Options: nosniff
ETag: W/"8a6665ffb7d45c2de131a910f5f5be15"
X-Frame-Options: SAMEORIGIN
X-Cache-Info: cached
Referrer-Policy: strict-origin-when-cross-origin
CF-Cache-Status: DYNAMIC
cf-request-id: 03febcd5310000d224e9a21200000001
Server: cloudflare
CF-RAY: 5b4497351a63d224-MAN

Note that X-Cache-Info is a header sent by my origin, it’s still not been cached by Cloudflare. I’d expect to see cf-cache-status: HIT given the origin cache headers, but can’t persuade it to work.

Static file extensions (eg .jpg) are successfully getting cached. If possible I’d rather rely on our Cache-Control headers than custom Cloudflare Page Rules.

You would need to create a Page Rule for the feed URL with “Cache Level: Cache Everything”, otherwise Cloudflare won’t cache that page. With cache everything I believe Cloudflare would respect your Cache-Control header.

1 Like

Well that’s weird - I definitely tried that setting earlier, and continued to just see CF-Cache-Status: DYNAMIC in the response. Maybe Page Rules take a while to take effect?

Also, “Cache Everything” is badly named, right? It won’t actually cache things that are Cache-Control: private ?

Sometimes they do. I usually clean the cache after updating then.
Developer mode is a good feature to enable if you are trying things out.

It won’t.

This article explains how Cloudflare decides what to cache and what not to cache:

2 Likes

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