Clear the Cache by Calling the Function Hook

Clear the Cache by Calling the Function Hook

by admin

You can use hooks to clear cache at specific points in the execution of the code. By strategically placing cache flush hooks in your code, you can ensure that caches are refreshed when needed.

1. Clearing All Cache

Simply call this function in your theme’s functions.php file or in a custom plugin to clear the entire cache. Clearing all cache triggers the “preload” feature and the preload feature starts working if the preload feature is enabled.

// Clear all cache
wpfc_clear_all_cache();

2. Clearing Cache for All Sites

If you’re running a WordPress Multisite installation and want to clear the cache for all sites within the network, you can use the following function. This function is useful in multisite environments where changes affect multiple sites, ensuring that the cache is cleared network-wide.

// Clear cache for all sites
wpfc_clear_all_site_cache();

3. Clearing All Cache and Minified Resources

This is beneficial when you’ve made changes to your stylesheet or javascript files, ensuring that visitors receive the most recent updates to these files.

// Clear all cache with minified sources
wpfc_clear_all_cache(true);

4. Clear Cache for Posts, Pages, or Custom Pages

This function takes a single parameter – the ID of the post, page, or custom page for which you want to clear the cache. The cache of the post’s tags, archive, and category is also cleared.

The example provided demonstrates how to clear the cache for a post with ID 1923:

// Replace 1923 with the ID of the content you want to clear the cache for
wpfc_clear_post_cache_by_id(1923);

Important Notice for WPML Users

If you are using the WPML plugin, you should disable the ‘Make themes work multilingual’ option as shown below. Otherwise, it will return the default language URL.

Related articles

Clear Cache Process
Clear Cache Process

WP Fastest Cache does not clear the cache instantly not to increase the CPU usage.

Placeholder Image
How to Remove the Footer Comment

By default, WP Fastest Cache adds an HTML comment in the page footer that indicates when and for how long…

Placeholder Image
How to Clear All The Cache After Update Post

Follow the link: http://www.wpfastestcache.com/tutorial/to-clear-cache-after-update/

Ready to get started?

Purchase your first license and see why 1,500,000+ websites globally around the world trust us.