Trying to cache an API endpoint with Page Rules but keep getting Cf-Cache-Status: DYNAMIC

I want to cache two endpoints (URLS) which return JSON content and are hosted on a Kinsta server.

Requests for both endpoints follow the same pattern like:
https://api.websitecarbon.com/site?url=example.com

I want each unique request to cache for a day.

I have set up page rules for the urls like so:

api.websitecarbon.com/site*
Cache Level: Cache Everything, Edge Cache TTL: a day Enabled

api.websitecarbon.com/b*
Cache Level: Cache Everything, Edge Cache TTL: a day

However, after repeated testing, I still get “Cf-Cache-Status: DYNAMIC”. Can anyone help me identify what’s not working with this setup?

Thanks, Jerome


Full response headers:

Date
Fri, 27 Aug 2021 11:16:57 GMT

Content-Type
application/json; charset=utf-8

Transfer-Encoding
chunked

Connection
close

Cf-Ray
6854e4025c6f40de-LHR

Access-Control-Allow-Origin
*

Vary
Accept-Encoding

Cf-Cache-Status
DYNAMIC

Expect-Ct
max-age=604800, report-uri=“https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct”

Ki-Edge
v=16.2

X-Content-Type-Options
nosniff

X-Edge-Location-Klb
1

X-Kinsta-Cache
HIT

Server
Cloudflare

Alt-Svc
h3-27=“:443”; ma=86400, h3-28=“:443”; ma=86400, h3-29=“:443”; ma=86400, h3=“:443”; ma=86400

It looks like this is Kinsta, and it’s quite likely that they control your Cloudflare settings, so your rules are being ignored. Have you asked them about this?

Thanks for your reply.

This site isn’t using the Kinsta Cloudflare integration, just a standard setup on Cloudflare so I don’t know how Kinsta would override the Cloudflare settings without it showing up in the headers?

I have asked them and they thought it would be something to sort out on the Cloudflare side. However, I’ll go back to them next week to have them take another look.

1 Like

But I do see something in the headers:

X-Kinsta-Cache
HIT

My suspicion, now that I think about it, is that if you point your DNS entry to Kinsta, it’s already proxied by Cloudflare for Kinsta, so their settings take precedence.

Have you tried any other types of Page Rules, such as a Forwarding URL for some made-up path to see if that happens?

And just now I decide to actually look at that hostname. It’s a CNAME to Kinsta:
api.websitecarbon.com is an alias for websitecarbonapi.hosting.kinsta.cloud.

No wonder your settings aren’t working.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.