Cloudflare cache not purgin after API request

I want to use the API to purge the cache on my Drupal site.

    $config = $this->config('mtn.cloudflare.settings');

    $config->set('cloudflare_zone_id', $form_state->getValue('cloudflare_zone_id'));
    $config->set('cloudflare_authorization', $form_state->getValue('cloudflare_authorization'));
    $config->save();

    $zone_id = $config->get('cloudflare_zone_id');
    $api_key = $config->get('cloudflare_authorization');

    $cURLConnection = curl_init("https://api.cloudflare.com/client/v4/zones/{$zone_id}/purge_cache");

    curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, [
      'accept: */*',
      'X-Auth-Email: [email protected]',
      "X-Auth-Key: {$api_key}",
      'Content-Type: application/json'
    ]);
    
    $data = ["purge_everything" => true];

    curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);
    
    $apiResponse = curl_exec($cURLConnection);
    curl_close($cURLConnection);

When I click on the button responsible for calling the script, it says that the cache was purged, and I can see the API response in the log like the following:

{ "result": { "id": "98f5qwdqd92a2d827c4qdqdqwd99d" }, "success": true, "errors": [], "messages": [] }

However, I have a CSS file with new code, and when I look at the CSS file, I notice that the code didn’t change, which means that the cache is not being purged.

Is there anything else I need to do to purge the cache?
How can I confirm that it’s not a cloudflare cache issue?

If it’s a Purge Everything, that should do it. Are other files showing a MISS at first request? How about that CSS file?

So, at first request, I created the file, wrote things in it, and could see everything when accessing through the browser. Its a css file for fonts. After adding things for the second time around and refreshing the browser, I didnt see the changes.
1 - Via ssh I navigated to the file and could see my changes. From the browser, still nothing.
2 - I deleted the file from the server, but can still see it through the browser with the old fonts.

I don’t see anything about purging the cache after you made these changes.

Sorry, I meant to say that those were the things I did before purging the cache.
I now also purged the cache through cloudflare dashboard and nothing. Note that I already deleted the file from the server, so, the correct behaviour would be to show nothing/404.

What’s the URL of the CSS file?

https://lab1.onlinecms.mtn.co.za/sites/default/files/vivid-fonts.css

I dont think that this has anything to do with cloudflare now.
If I append a query string to the link I see the correct result.
So, in summary, I need to add query string to the file of which the value has to be the current timestamp.
https://lab1.onlinecms.mtn.co.za/sites/default/files/vivid-fonts.css?timestamp=currenttimestamp

Using Query string is a workaround if you’re using Cloudflare’s Standard cache setting. But I do see you have server cache (Varnish?) as well as Cloudflare cache. Still, if you’ve purged everything at Cloudflare, it would still pull the old copy from the server if you haven’t purged that cache as well.

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