BUG: Cloudflare WordPress plugin does not purge URL cache when worker used for cache instead of cache everything rule

Hi,

I found a bug in the Cloudflare WordPress plugin.

When using a Worker to cache website content instead of a Cache Everything rule while using the Cloudflare WordPress plugin with Auto Purge Content On Update enabled, cache is NOT purged when a post is updated.

This happens because of lines 207 to 210 in Hooks.php:

if (!$hasCacheOverride && !$this->isAutomaticPlatformOptimizationEnabled()) {
    $this->logger->debug("cache everything behaviour and APO not found, filtering URLs to only be those that are cacheable by default");
    $urls = array_filter($urls, array($this, "pathHasCachableFileExtension"));
}

This code checks for the presence of a Cache Everything rule in the Page Rules section of the Cloudflare dashboard. If such a rule is found, then the $urls array is populated with the URLs and purge ensues. But if the rule is not found, then $urls becomes an empty array and no URLs are purged. In my case, since a worker is used for cache and there’s no Cache Everything rule, $urls is empty and URLs are not purged when a post is updated.

I was able to “trick” the system into thinking I had a Cache Everything rule by creating a Cache Everything rule on a non-existing URL and enabling the rule. By doing this, the plugin works as intended and properly purges the URLs on content update.

So, if anyone is using workers to cache their website content and has any cache purge issues with the Cloudflare WordPress plugin, you can try my fix for the time being.

1 Like