While working on PHP compatibility fixes for a new customer I discovered a few things about how Kinsta’s caching system works. It’s actually quite easy to programmatically purge Kinsta’s cache for either the entire site or a single page. Check out these PHP code examples.
Purge the entire Kinsta’s cache.
$response = wp_remote_get( 'https://localhost/kinsta-clear-cache-all', [ 'sslverify' => false, 'timeout' => 5 ] );
To purge individual pages you can visit any page with /kinsta-clear-cache/ added between the domain name and the page name. For example, visiting
https://captaincore.io/kinsta-clear-cache/blog/ would purge the cache for the page
Purge individual page from Kinsta’s cache.
$page = "blog/my-awesome-blog-post/"; $response = wp_remote_get( home_url(). "/kinsta-clear-cache/$page", [ 'sslverify' => false, 'timeout' => 5 ] );
Kinsta’s cache generally works great without any customization.
If you use WordPress out of the box you should never have to do anything special to purge Kinsta’s cache. That’s because the caching system is smart enough to purge itself whenever the content is changed. That said, if you’re working with custom code that is making content changes, it’s possible for related pages to become outdated. A good example of this would be a custom WordPress REST endpoint that receives data from an outside source which is shown on a custom page template. This would be a scenario where purging that custom page programmatically would be required.