How to directly update Cloudfare cache

Hello,
I want to set a page rule to Cache everything and after that, I want to open a cache for a specific page make some changes in the HTML and save it back directly to Claudfare, is it possible? How? thank you a lot.

No, I am afraid it is not. You will need to purge the cache in that case, either completely or just for that particular URL.

Depending on what you are using you could also look into APO (Introducing Automatic Platform Optimization, starting with WordPress) or Worker Sites or Cloudflare Pages. Particular the last two will be actually hosted services, but it might require a redesign of your current site and would be paid.

The easiest option might be to have the cache-everything rule in place and selectively purge the cache whenever you change a URL. You could also look into the API (api.cloudflare.com) to do this automatically.

1 Like

Thank you a lot for your time. APO is not a thing that would help…I could use the API, delete the specific URL from the cache and then fetch the cache of that page to Claudfare. Anyway, I was trying to understand the workers and try to use the API in it to do this, but I´m kinda lost in it.

Could you please navigate me how to use API to do this:

deleteCacheOfURL(forbino.com/the-page/);
fetchUrlToClaudFare(forbino.com/the-page/);

Thank you a lot.

It actually might, but it certainly does depend on your use-case and if you use Wordpress (for the time being they focus only on that).

You can only purge a URL from the cache, you can’t “fetch” it. As for purging it, the aforementioned API link has all the details on what to do.

https://api.cloudflare.com/#zone-purge-files-by-url

Cloudflare API v4 Documentation - I manage to write a script that deletes the cache of the specific page, it returns true … { “result”: { “id”: “8xxx5” }, “success”: true, “errors”: , “messages”: }, but it does not delete the HTML page of that URL. So I have logged into the claudfare and try the “Custom Purge”, but the result is the same, the page is still in the cache. Any idea why?

How I tested that the page is still in the cache:

I have waited for more than 30s, than I used GTmetrix and test the page there => cf-cache-status
HIT.

If you specified the right URL it should purge that URL globally. As you mentioned it can take up to a minute. The Age header will tell you how long that resource has been in the cache.

I would suggest you double check your script and make sure it really matches the example and that you provide the correct URL. If everything checks out and it still does not work you could open a support ticket, but generally speaking aforementioned API call should do exactly that.

Also, assuming you are talking about forbino.com it would not seem as if you had a cache-everything rule in the first place as your HTML URLs are all not cached. In that case that might be some issue with a server-side cache, but Cloudflare would not be involved in the caching.

It is but “Cache everything” is set only for forbino.com/akcie/* - I want to test it on just a part of the website.

Anyway. It seems it works, but it works differently than I thought it will.

Let me explain - I have tested it on this URL https://forbino.com/akcie/dividendove-investovani/ :

  1. I have loaded the page from Australia (using VPN) and it cached the page, GT Metrix. cache age 18070

  2. I have purged the cache of the URL, have waited a few minutes and test it again on GTMetrix. It has been slower - Largest Contentful Paint 2.1s instead of 0.7s before, but the page was cached as well - 5s age.

  3. I have purged the cache again and waited about 20-30minutes, it has been cached as well and it was fast 0,9s. GTmetrix.

I don’t know why there is such a big difference in speed and I´m surprised that the Claudfare caches the page so quickly after I purge it and without any previous visit to that page after the purge…I´m not sure if it can be influenced by the GTmetrix and how their speed testing works, they might send more requests during the test and that might be the reason why it´s already cached when it shows the results, what do you think?.

What you described is exactly how it works. When uncached the first request will always go to your server and hence be a tad slower. But it won’t cache it without a “visit”, so in your case there will have been a previous request or the service in question ran a request earlier.

Your site generally loads fine and when cached in about half a second.

Thank you for your help, Sandro. I appreciate it.

You need to deploy Cloudflare Worker on your site and disable Cache Everything, then:

1 Like

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