-
Notifications
You must be signed in to change notification settings - Fork 17
Clearing the Cache Dynamically
You can call any class method that is declared as a public function in quick-cache.inc.php
or quick-cache-pro.inc.php
using $GLOBALS['quick_cache']->any_public_method()
.
For example, if you wanted to clear the cache every time a post was saved or updated (i.e., when the save_post
action is fired), you could add the following to your theme's functions.php
file:
add_action( 'save_post', 'my_custom_clear_cache', 10, 1 );
function my_custom_clear_cache( ) {
$GLOBALS['quick_cache']->clear_cache();
}
Using the save_post_{$post_type}
hook, which is fired whenever that custom post type is created or updated (see docs), you can add something like the following to your theme's functions.php
file, or to a MU-Plugin, to clear the cache for a given page whenever a post with that custom post type is saved:
add_action( 'clear_cache_for_page_id_5', 'save_post_my-custom-post-type', 10, 1 );
function clear_cache_for_page_id_5( ) {
$GLOBALS['quick_cache']->auto_purge_post_cache(5);
}
You'll want to change 5
to the ID of the Page/Post whose cache you'd like to clear when that custom post type is saved, and you'll want to change my-custom-post-type
to the actual name of your Custom Post Type.
Using the save_post
hook, which is fired whenever a post created or updated (see docs), you can add something like the following to your theme's functions.php
file, or to a MU-Plugin, to clear the cache for a given page
add_action( 'clear_cache_for_page_id_5', 'save_post', 10, 1 );
function clear_cache_for_page_id_5( ) {
$GLOBALS['quick_cache']->auto_purge_post_cache(5);
}
You'll want to change 5
to the ID of the Page/Post whose cache you'd like to clear.