Home > Net >  How to force cloudflare to cache api which it keeps categorizing as CF-Cache-Status: DYNAMIC?
How to force cloudflare to cache api which it keeps categorizing as CF-Cache-Status: DYNAMIC?

Time:11-04

I am trying to cache an api get request that produces json - using cloudflare by page rules : Cache Everything with Edge Cache TTL > 0.
No matter what I try - I am unable to get past: CF-Cache-Status: DYNAMIC!
Referring to the documentation of page rules I even tried a sample xml file - but the same issue persists.

Page rule:

https://.com:8443/cache_*
Cache Level: Cache Everything

Using cf workers too - availed no result. The api is being served by Spring Boot, have tried virtually all combination of headers. What am I doing wrong?

CodePudding user response:

You'll want to read up on how to use Cache-Control header, as this will enable you to control the caching behavior on file types that Cloudflare would not normally cache -

https://developers.cloudflare.com/cache/about/cache-control

There are some cases where Cloudflare will never cache the response (for your safety) however. For example, if the server is returning a Set-Cookie response header.

CodePudding user response:

Oops! I was using an unsupported port. Apparently 8443 in NOT supported for caching. This was pointed out by M4rt1n at cloudflare forum:
https://community.cloudflare.com/t/unable-to-cache-json-api-with-page-rules-stays-at-dynamic/322632/4

https://support.cloudflare.com/hc/en-us/articles/218411427 > only port 80, 8080 & 443 supported for caching.

Cloudflare would have simply said - “8443 is not supported for caching” when i was trying to add the page rule with cache everything

  • Related