Caching Rest API

I’m attempting to force caching on Rest API paths, ignoring no-cache or similar headers. I’ve set up a page rule to cache everything, as I saw in a previous post, but this didn’t seem to do anything.

However it doesn’t seem to be working. An example path would be or even just the root path, which returns a heartbeat.

I have a bit of a bandwidth problem that I’m trying to conquer.

Hi @tobiah
there are two possible causes for this:

  1. PageRule is not matching
  2. another matching PageRule for the URL is above this PageRule.

So to figure things out, please change the PageRule from ** to*.

And second, please post the overview of ALL of your PageRules here as a screenshot, so we can proceed looking into this.


Here’s my overview:

Ok thanks, now please change the first PageRule according to my previous message:


already see a HIT :wink:

1 Like

yup, i was also doing that. It’s changed as described

shoot, now i am too. that’s… weird, i’d tried initially with this wildcard style… either way, thank you very much, @M4rt1n!

Perfect, seems to work.


you probably wanted to match both Schemes “HTTP” and “HTTPS” by implementing the asterisk at the begining, but that would match ALL subdomains that ends with “api” (basically ALL subdomains that do not exist if you have the DNS subdomain wildcard) and does not match this one.
If you want to match both schemes, just leave the scheme away, like* as this then matches both schemes.

So since you anyway just deliver content on the HTTPS scheme please always set the “Cache Everything” rules to HTTPS :slight_smile:

You’re welcome! Hope you like this community :slight_smile:
If yes, please subscribe and leave a like xD

1 Like

So, caching in general is working, but it doesn’t seem to be respecting the times I set in ether Caching / Configuration

or in the page rule.

I can’t attach a second screenshot, but I added just a setting for Browser Cache TTL set to 2 minutes, but it doesn’t seem to respect that.

What you probably want is “Edge TTL”, not Browser TTL. Please add in the PageRule this setting:

Edge Cache TTL: 2 hours

since this is the lowest you can go with a non-Enterprise account.

Browser Cache TTL: how long it shall be stored on the visitors device
Edge Cache TTL: how long it will be stored at Cloudflares Edge.

Yeah, that’s not quite low enough… So it sounds like this can’t really work, unfortunately, for my use-case, without upgrading that is.

Just feel free to set the Edge Cache TTL to one month, and instead better trigger an API request to clear the URLs, everytime the content changes. This will be way better :slight_smile:

In worst case you can trigger the API by a 2 min cron. But please invalidate cache just on changes. Thats always the best case.

ah! that does make sense. I’ll give that a shot.

Please don’t go for the 2min-cron, way better is to invalidate on a change-event if you can hook into it.

Report back and we’ll see how we can solve that the best way.

Please don’t go for the 2min-cron, way better is to invalidate on a change-event if you can hook into it.

I’m going for over 2 minutes for now, but that coincides with the other cron I already have for updating the specific endpoints that update that fast. I did a purge everything, and that’s working.

If you already update your content with a cron, just append the PurgeScript with a ‘&&’ to it, so it runs after the first script/command exited successfully.

something like this:

*/5 * * * * bash -c 'command1 && command2'


*/5 * * * * /bin/bash -c 'command1 && command2'

After this, wait untill you are 100% certain the content did update and see it the change also gets reflected on Cloudflare.

yup, that’s just what I did, and it’s working thusfar.

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