• Resolved Pradeep Augustine

    (@praderj)


    Hi Team,

    I recently switched from WP Super Cache to WP-Optimize and I’m looking for an option to prevent automatic cache purging on plugin activations, updates, and post updates.

    My website is content-heavy (around 30,000 posts) and doesn’t change often, so I’d like to completely disable automatic cache purging to improve performance and reduce server load.

    I couldn’t find a setting in the dashboard for this — could you please advise if there’s a way (or a filter/hook) to disable all automatic cache purges?

    Thanks and regards,
    Pradeep K A

    The page I need help with: [log in to see the link]

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Support vupdraft

    (@vupdraft)

    You can try adding the following filter;

    add_filter(‘wpo_purge_post_on_update’, ‘__return_false’);

    You can also set your cache lifespan to 0, so that cache is preloaded only when the cache is emptied

    Thread Starter Pradeep Augustine

    (@praderj)

    Thank you so much for the help. I will try the filter.

    Thread Starter Pradeep Augustine

    (@praderj)

    Hi Team, I tried the filter, but still Plugin updates cleared the cache.

    Do you have any other solution?

    Plugin Support jbgupdraft

    (@jbgupdraft)

    Hi,

    Can you try this? This needs to be created as an mu-plugin since this will not be triggered in your theme functions.php upon a plugin update. If you don’t have an mu-plugins folder inside your wp-content folder you can create it manually and then add this as a new PHP file:

    <?php

    /**

    * Plugin Name: WPO Update Listener

    * Description: Fires a custom action when plugins or themes are updated.

    */

    add_filter('wpo_purge_cache_hooks', 'disable_cache_purge_wpo', 10, 1);

    function disable_cache_purge_wpo($actions){

    foreach($actions as $actionKey => $actionValue){

    if(!is_array($actionValue)){

    if($actionValue == "wpo_active_plugin_or_theme_updated"){

    unset($actions[$actionKey]);

    }

    }

    }

    return $actions;

    }

    I’ve tested this on one of my sites hopefully it works for you too!

    Thread Starter Pradeep Augustine

    (@praderj)

    @jbgupdraft , thanks for the snippet.

    I tried it as a mu plugin. Still no luck. I deactivated a plugin and it cleared the cache automatically. It would be great you bring that option to the plugin by default in the future updates.

    Thank you!

    Plugin Support jbgupdraft

    (@jbgupdraft)

    Hi,

    Plugins being deactivated would be a different action that runs. I’ll continue looking through the code to see if I can find an additional action or filter to hook into and send you another snippet for the MU-Plugin.

    Plugin Support jbgupdraft

    (@jbgupdraft)

    Hi,

    Thanks for your patience! I was able to locate another filter that can be hooked into on plugin activation / deactivation that will stop the page cache from clearing automatically. If you can replace the existing MU-Plugin with the snippet below, let me know if it works for you!

    <?php 

    /**

    * Plugin Name: WPO Update Listener

    * Description: Fires a custom action when plugins or themes are updated.

    */

    add_filter('wpo_purge_cache_hooks', 'disable_cache_purge_wpo', 10, 1);

    function disable_cache_purge_wpo($actions){

    foreach($actions as $actionKey => $actionValue){

    if(!is_array($actionValue)){

    if($actionValue == "wpo_active_plugin_or_theme_updated"){

    unset($actions[$actionKey]);

    }

    }

    }

    return $actions;

    }

    add_filter('wpo_purge_page_cache_on_activate_deactivate_plugin', '__return_false');


    Thread Starter Pradeep Augustine

    (@praderj)

    Hi @jbgupdraft,

    The new snippet you provided worked; however, it cleared the minified files, which caused errors on the frontend since the cached files were still referring to them.

    Can you help to prevent that as well?

    Thank you!

    Plugin Support jbgupdraft

    (@jbgupdraft)

    Hi,

    Glad to hear we’re making some progress. Just to double check, was the minify cached cleared for you when deactivating a plugin or running a plugin update?

    Thread Starter Pradeep Augustine

    (@praderj)

    Thank you. I updated a plugin and the minified files got cleared.

    Plugin Support jbgupdraft

    (@jbgupdraft)

    Hi,

    I was able to find a couple of actions to remove for the minification cache. I’ve tested this on one of my sites and updating a plugin has not been purging the minified files. Hopefully it works out for you too!

    <?php

    /**

    * Plugin Name: WPO Update Listener

    * Description: Fires a custom action when plugins or themes are updated.

    */

    add_filter('wpo_purge_cache_hooks', 'disable_cache_purge_wpo', 10, 1);

    function disable_cache_purge_wpo($actions){

    foreach($actions as $actionKey => $actionValue){

    if(!is_array($actionValue)){

    if($actionValue == "wpo_active_plugin_or_theme_updated"){

    unset($actions[$actionKey]);

    }

    }

    }

    return $actions;

    }

    add_filter('wpo_purge_page_cache_on_activate_deactivate_plugin', '__return_false');

    add_action('plugins_loaded', 'prevent_minify_cache_clear');

    function prevent_minify_cache_clear(){

    remove_action('upgrader_process_complete', array('WP_Optimize_Minify_Cache_Functions', 'cache_increment'));

    remove_action('wpo_active_plugin_or_theme_updated', array('WP_Optimize_Minify_Cache_Functions', 'reset'));

    }
Viewing 11 replies - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.