And your answer is completely unrelated to what I explained…
I’m saying that when the integration is enabled API calls are being made to cloudlfare on each request… And those api calls are synchronous so blocking script execution, which means that every non cached page gets an increase of 4s TTFB
cloudflare_get_zone_id + cloudflare_clear_cache is executed twice on each page because a non cached post is being updated (eg when adding to the cart, passing an order, posting a comment), the result of the first request can easily and SHOULD BE cached, as for the cache clear it should be proxied and register a wordpress cron job to execute the api call on the next cron run, not in sync with the request or the user is subject to terrible waiting times
Another possibility way easier to implement than cron job is to modify the function so that it is non blocking and runs only once
public static function cloudflare_clear_cache($email = false, $key = false, $zoneid = false){
static $executed = false; //diff
if ($executed) { //diff
return;
}
if(!$email && !$key && !$zoneid){
if($cdn_values = get_option("WpFastestCacheCDN")){
$std_obj = json_decode($cdn_values);
foreach ($std_obj as $key => $value) {
if($value->id == "cloudflare"){
$email = $value->cdnurl;
$key = $value->originurl;
break;
}
}
if($email && $key){
$zone = self::cloudflare_get_zone_id($email, $key, false);
if($zone["success"]){
$zoneid = $zone["zoneid"];
}
}
}
}
if($email && $key && $zoneid){
$header = array("method" => "DELETE",
'headers' => array(
"X-Auth-Email" => $email,
"X-Auth-Key" => $key,
"Content-Type" => "application/json"
),
"blocking" => false, //diff
"body" => '{"purge_everything":true}'
);
wp_remote_request('https://api.cloudflare.com/client/v4/zones/'.$zoneid.'/purge_cache', $header);
$executed = true; //diff
}
}
Until this is solved, the cloudflare cache integration is unusable.
-
This reply was modified 4 years, 2 months ago by Tofandel.
-
This reply was modified 4 years, 2 months ago by Tofandel.
-
This reply was modified 4 years, 2 months ago by Tofandel.