Why is an HTTP response with Cache-Control: public, max-age=86400 not being cached by Cloudflare?

77 views Asked by At

Our server (origin server) is sending the following HTTP response back to Cloudflare, including "Cache-Control: public, max-age=86400", expecting Cloudflare to cache it:

HTTP/2 200
date: Tue, 24 Oct 2023 13:31:00 GMT
content-type: application/json
cache-control: public, max-age=86400
expires: Wed, 25 Oct 2023 13:31:00 GMT
strict-transport-security: max-age=31536000
x-content-type-options: nosniff
last-modified: Tue, 24 Oct 2023 13:31:00 GMT
vary: Accept-Language

But Cloudflare is then sending back to the client the following response with "cf-cache-status: DYNAMIC" stating that it was not cached even when the Cache-Control and Expires header are set.

HTTP/2 200
date: Tue, 24 Oct 2023 13:31:00 GMT
content-type: application/json
cache-control: public, max-age=86400
expires: Wed, 25 Oct 2023 13:31:00 GMT
strict-transport-security: max-age=31536000
x-content-type-options: nosniff
last-modified: Tue, 24 Oct 2023 13:31:00 GMT
vary: Accept-Languagecf-cache-status: DYNAMIC
server: cloudflare
cf-ray: 81b293ddbb18a780-EZE

Any insight of why is this happening?

Cloudflare documentation in https://developers.cloudflare.com/cache/concepts/default-cache-behavior/ states that "Cloudflare does cache the resource when the Cache-Control header is set to public and max-age is greater than 0."

We added "Cache-Control: public, max-age=86400" and also "Expires" header set to 24 hours after current time, but Cloudflare is still not caching the resource.

1

There are 1 answers

0
kyouhei On

What is your URL?

Cloudflare only cache the listed file extensions in your URL.

For example, if your URL is like *.html, it should be treated as DYNAMIC by default.

If you would like to cache such the resource, you have to configure Cache Rules with the expression like (http.request.uri.path.extension eq "html")