Try our conversational search powered by Generative AI!

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


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:

The code is similar to this example:

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

Edited, Sep 15, 2020 8:08

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.

Edited, Sep 15, 2020 12:15

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?

Sep 15, 2020 12:38

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).

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.