How to get cf-cache-status HIT from Web API controller responses on the DXP?

Vote:
 

I have confirmed that my API response has Cache-Control: public, max-age=30 but DXP environment response still says cf-cache-status DYNAMIC.

CF docs says:

  • Otherwise, if Cache-Control is set to public and the max-age is greater than 0, or if the Expires header is a date in the future, Cloudflare caches the resource.

  • If both max-age and an Expires header are set, max-age is used.

I've also read: https://world.episerver.com/documentation/developer-guides/digital-experience-platform/development-considerations/cdn-recommendations/#ConfiguringCacheHeaders

The code is similar to this example: https://stackoverflow.com/questions/15911356/setting-http-cache-control-headers-in-web-api/22620144#22620144

The method is GET, content-type is application/json and the URLs are /api/something-cool/ without querystrings.

#227870
Edited, Sep 15, 2020 8:08
Vote:
 

Hi Johan

I've has this issue before. No matter what you set in origin response headers, Cloudflare will only cache static content. By default.

You need to contact Episerver Support and have them make a Page Rule for the /api/* URL pattern. Then they can override the Cache Level setting, and set it to Cache Everything.

With this in place, Cloudflare will respect your origin cache headers.

I described the steps in this blog post.

#227877
Edited, Sep 15, 2020 12:15
Vote:
 

Thanks! I will check with support. I know they usually aren't superhappy with custom CF config but maybe these are easier to get in place?

#227879
Sep 15, 2020 12:38
Vote:
 

I know. The support is very cautios. But they were helpful when I asked a second time.

In some cases, you may need to make up a custom cache key format for the page rules. Mostly if you need to vary by cookies or custom headers (documentation page). But be careful with combinations that results in too many different variants (high cardinality).

#227883
Sep 15, 2020 17:21
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.