Disable All Automatic Cache Clearing

Note: This tutorial refers to WordPress action hooks. If you understand code and are not familiar with the concept yet, you can learn more about it here.

There are numerous actions that can trigger a full or partial deletion of the cache.

The most common are:

  • Clear Cache Lifespan
    The whole cache will be deleted automatically according to the time period you specify in the Basic Options.
  • New Content
    When you publish new content or update/edit existing content, the cache for that and related content (e.g. taxonomy archives) will be cleared and preloaded. You can learn more about that here:
    How Is The Cache Preloaded

Here is the full list of other actions that trigger full cache deletion:

  • changing themes
  • creating/updating/deleting users (if you run a busy e-commerce site with a lot of orders, those orders could be creating new users and therefore causing frequent cache deletion)
  • updating navigational menus
  • updating theme options
  • creating/updating/deleting sidebar widgets
  • creating/updating/deleting categories, tags, or permalink structures
  • creating/updating/deleting terms
  • creating/updating/deleting links (the post type “Link” that was removed from WorPress core in version 3.5, but may still be used via a plugin)
  • when any options are saved in the Customizer
  • when the Avada theme clears its own cache

Actions that will trigger partial cache deletion:

  • creating/updating/deleting posts or pages
  • creating/updating/deleting comments on a post

Avoid Automatic Cache Clearing

If you want to prevent these actions, you can easily do so by using the following in a MU plugin.

Custom MU Plugin

Follow the general instructions in this article:
How to Make a Custom (MU) Plugin

1
Create a folder named mu-plugins in your wp-content folder.
In case a mu-plugins folder already exists, don’t create a new one, just use the existing one.
2
Using a basic text editor create a new file and put the following code in it:
<?php
defined( 'ABSPATH' ) or die( 'Cheatin&#8217; uh?' );
/**
 * Plugin Name: WP Rocket | Disable Automatic Cache Purge
 * Description: Disables automatic cache purging in WP Rocket.
 * Author:      WP Rocket Support Team
 * Author URI:  http://wp-rocket.me/
 * License:     GNU General Public License v3 or later
 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
 */

// Disables the deletion of the entire cache.
add_action( 'wp_rocket_loaded', 'rocket_remove_all_purge_hooks' );

/**
 * Remove all of WP Rocket’s cache purging actions.
 * @return void
 */
function rocket_remove_all_purge_hooks() {

	// WP core action hooks rocket_clean_domain() gets hooked into.
	$clean_domain_hooks = array(
		// When user changes the theme
		'switch_theme',
		// When a user is added
		'user_register',
		// When a user is updated
		'profile_update',
		// When a user is deleted
		'deleted_user',
		// When a custom menu is updated
		'wp_update_nav_menu',
		// When any theme modifications are updated
		'update_option_theme_mods_' . get_option( 'stylesheet' ),
		// When you change the order of widgets
		'update_option_sidebars_widgets',
		// When category permalink prefix is update
		'update_option_category_base',
		// When tag permalink prefix is update
		'update_option_tag_base',
		// When permalink structure is update
		'permalink_structure_changed',
		// When a term is created
		'create_term',
		// When a term is updated
		'edited_terms',
		// When a term is deleted
		'delete_term',
		// When a link (post type) is added
		'add_link',
		// When a link (post type) is updated
		'edit_link',
		// When a link (post type) is deleted
		'delete_link',
		// When resulty are saved in the Customizer
		'customize_save',
		// When Avada theme purges its own cache
		'avada_clear_dynamic_css_cache',
	);

	// WP core action hooks rocket_clean_post() gets hooked into.
	$clean_post_hooks = array(
		// Disables the refreshing of partial cache when content is edited
		'wp_trash_post',
		'delete_post',
		'clean_post_cache',
		'wp_update_comment_count',
	);

	// Remove rocket_clean_domain() from core action hooks.
	foreach ( $clean_domain_hooks as $key => $handle ) {
		remove_action( $handle, 'rocket_clean_domain' );
	}

	// Remove rocket_clean_post() from core action hooks.
	foreach ( $clean_post_hooks as $key => $handle ) {
		remove_action( $handle, 'rocket_clean_post' );
	}

	remove_filter( 'widget_update_callback'	, 'rocket_widget_update_callback' );
}
	
3
Save the file as wp-rocket-no-purge.php
4
Upload this file to the mu-plugins folder created in step 1.
5
Finally, make sure to deactivate and re-activate WP Rocket.