How to add cache-busting to XFtoWP Requests
Table of Contents
- Clear cache after new comments are loaded
- Clear the cache on general data refreshes
To help ensure the most latest data from your forum is showing, it may be worthwhile to manually clear the cache if you have a more aggressive caching plugin setup.
If it seems to take longer than usual for refreshed forum and comments data to show up, the culprit may be that your page is displaying an old version of the page before XFtoWP ran one of its refresh processes.
Most caching plugins offer template functions that allow you to clear the cache whenever the function is called, and XFtoWP offers available hooks that let you plug those cache-busting functions into plugin requests.
Keep in mind, the whole idea of showing a cached page is to deliver static pages that do not require the browser to crunch dynamic data from the database.
By purging the cache too often, you may negate some benefits of caching to begin with. However, it is worth testing on your setup to see how your site performs.
Clear cache after new comments are loaded
Depending on your Refresh time set in WP admin > XF > Site Setup, a user will trigger the comments refresh process which will update the latest replies shown on a page.
You can add your cache function to the following hook in your child theme functions.php
file, or anywhere else you execute custom code.
Please refer to your cache plugin’s developer documentation for the correct code to insert into the following hook:
/**
* Run cache-busting function after XFtoWP comments
* thread is refreshed.
*
* @since 1.0
*/
function my_child_theme_after_comments_refresh( $post_id ) {
// Add plugin cache-busting functions here.
// Use $post_id to target the cache for the current page only.
}
add_action( 'xfwp_after_load_comments', 'my_child_theme_after_comments_refresh' );
This hook is very limited in scope, and combined with the $post_id
, you can only target specific page caches to clear instead of your entire site every time.
Clear the cache on general data refreshes
To target the general site refresh syncing process that happens every X minutes on your site (as configured in WP admin > XF > Site Setup > Refresh time) you can call the following hook:
/**
* Run cache-busting function after XFtoWP refreshes data.
*
* @since 1.0
*/
function my_child_theme_after_refresh() {
// Add plugin cache-busting functions here.
}
add_action( 'xfwp_after_refresh_data', 'my_child_theme_after_refresh' );
This hook applies sitewide and should be used with consideration as it will clear the cache every time XFtoWP reloads it data.