Support » Plugin: W3 Total Cache » Need a hook to prevent W3TC from flushing whole object cache on update_option

  • I have an issue with the way W3TC automatically flushes the whole object cache every time a site option is updated.

    This happens in /lib/WC/Plugin/ObjectCache.php in the W3_Plugin_ObjectCache object:

    function on_change_option($option) {
            static $flushed = false;
    
            if (!$flushed) {
                if ($option != 'cron') {
                    $flush = w3_instance('W3_CacheFlush');
                    $flush->objectcache_flush();
                    $flushed = true;
                }
            }
        }

    There is no way to hook in and prevent the flushing from happening for option updates, contrary to the post update flushing which offers a hook in the w3_is_flushable_post function.

    In my case, the problem is caused by the WP Slimstat plugin which updates the slimstat_visit_id option on every visit to the site. So the result is that my whole object cache gets flushed several times per minute, rendering it useless.

    So my question is, could possibly make a hook to prevent the object cache from flushing on every option update? Possibly by filtering on the option name.

    Also I’m curious, why the need to flush the whole object cache on updates to a site option, or to all post updates? It seems to me that WP Core already uses the wp_cache_delete on a per item basis to invalidate all its entries in the object cache? Both when it comes to posts, meta, and options.

    This issue has been discussed before here:
    https://github.com/woothemes/woocommerce/issues/3014

    https://wordpress.org/plugins/w3-total-cache/

Viewing 1 replies (of 1 total)
  • Hi,

    we at Slimstat are very interested in finding a solution to this issue, but like it was said on the WooCommerce thread you mentioned, W3TC should implement some sort of switch or filter to allow admins to prevent this behavior. What we can do on our end is not to call update_option, and basically write our own function to update that counter in the database, thus bypassing the problem altogether.

    Keep us posted,
    Camu

Viewing 1 replies (of 1 total)
  • The topic ‘Need a hook to prevent W3TC from flushing whole object cache on update_option’ is closed to new replies.