Cloudabove has the ability to speed up a site by caching on the server. By default, this cache is cleared every 15 minutes. This speeds up the site quite a bit, but it also affects the display of content. For example, in my case, a product review posted by a user did not appear until 15 minutes later.
Clearing the cache is pretty simple. It is based on a GET request to https://scout.cloudabove.com/api/cache/purge
. It is important that the request comes from your server, otherwise the API will not accept the request.
In the case of Woocommerce reviews, we will use the comment_post
hook and the wp_remote_get()
function
function clear_server_cache($comment_id, $comment_approved) {
if($comment_approved == 1){
wp_remote_get('https://scout.cloudabove.com/api/cache/purge', array('timeout' => 5));
}
}
add_action( 'comment_post', 'clear_server_cache', 20, 2 );
In addition, we can clear the cache from the site’s admin area using the button
To make it available, you need to place this file scout-cache-helper.php in the wp-content/mu-plugins folder of our website.