Can't make cache proxy work with max-age

Hello there,

I’m trying to setup Cloudflare as a reverse proxy but I don’t manage to make it work.
Goal is to use max-age without revalidation (once you cache it, serve it, don’t ask).
I have a PHP script that produces XML and sends the following headers (origin server):

HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Wed, 01 Apr 2020 06:32:11 GMT
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Cache-Control: max-age=900

But after refreshing several times, CF-Cache-Status is always DYNAMIC (proxied by CF):

HTTP/1.1 200 OK
Date: Wed, 01 Apr 2020 06:33:22 GMT
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Cache-Control: max-age=900
CF-Cache-Status: DYNAMIC
Server: cloudflare
CF-RAY: 57d0473e6fbbbd82-AMS
Content-Encoding: gzip

Settings are default:
Domain proxied: YES
Caching level: Standard
Cache TTL: 4 hours
Always Online: ON
Development mode: OFF

Any ideas?
Thank you,
Ben

PS: I also tried with directives like immutable, only-if-cached, without any success.

Html content isn’t cached by default.

https://support.cloudflare.com/hc/en-us/articles/202775670-Customizing-Cloudflare-s-cache

https://support.cloudflare.com/hc/en-us/articles/200172516#h_a01982d4-d5b6-4744-bb9b-a71da62c160a

Hello cscharff,

Sorry to insist, but:

  1. It’s not HTML, it’s XML
  2. It’s actually not true, I’m currently serving another website (with a different framework) through CF, and HTML is properly cached with the max-age headers
  3. If it was true, the “Always online” feature (if origin server goes down, serve from CF) would be unrelevant.

I just don’t figure out how I manage to do this with another website (which uses Symfony) and not that one (raw PHP), despite headers and setup look identical.

XML is covered in the linked article(s). It is also not a content type cached by default by Cloudflare.

  1. From the first link:
  1. Verify your resources are cached by checking the cache response returned by Cloudflare.

Cloudflare caches XML responses when using Cache Everything . By default, jquery’s getScript explicitly bypasses cache by appending a timestamp query string unless the behavior is disabled. For further details on how to adjust Cloudflare’s behavior in regards to query strings, refer to our article on Understanding Cloudflare Caching Level.

  1. From the second link:

Cloudflare only caches based on file extension and doesn’t cache by MIME type. The Cloudflare CDN automatically caches files containing certain file extensions and doesn’t cache HTML by default:

  1. Always Online isn’t mentioned in either of the articles I linked to except as an ‘additional resource link’ at the end of the first.

DYNAMIC The resource was not cached by default and your current Cloudflare caching configuration doesn't instruct Cloudflare to cache the resource. Instead, the resource was requested from the origin web server. Use [Page Rules](https://support.cloudflare.com/hc/en-us/articles/200168306-Is-there-a-tutorial-for-Page-Rules-) to implement custom caching options.

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