Automattic / wp-memcached

Memcached Object Cache for WordPress.
https://wordpress.org/plugins/memcached/
GNU General Public License v2.0
157 stars 55 forks source link

[Feature request/question] How to disable for a single website in wpmu ? #161

Open mbautista opened 4 months ago

mbautista commented 4 months ago

Hello, Thank you for this module, it rocks :)

Is it possible to disable the cache object on a specific website in a wordpress network ? Is there any constant and/or filter we could use ?

As I could not find it I added a filter in the object-cache.php but I'm not sure if it's required and/or in the right place :

function wp_cache_set( $key, $data, $group = '', $expire = 0 ) {
        global $wp_object_cache;

        if ( defined( 'WP_INSTALLING' ) == false && apply_filters( 'ircf_wp_cache_disabled', false ) == false) {
                return $wp_object_cache->set( $key, $data, $group, $expire );
        } else {
                return $wp_object_cache->delete( $key, $group );
        }
}

Thank you very much :) Mathieu.

dd32 commented 2 months ago

Disabling the object cache for a specific site in a network is not something that should really be supported IMHO.

The reason is that WordPress has two different levels of cache - Per site cache groups, and global cache groups.

The global cache groups are shared between all sites on the network, and per-site caches are specific to the individual site.

Disabling the cache for a specific site would require keeping the global cache active, as otherwise any changes to network-data would change the DB without updating the cache, causing issues for other sites which retrieve it from the cache instead.

Perhaps the better question is, what's the use-case for disabling it for a specific site? Once that's answered we might be able to suggest ways forward.

mbautista commented 2 months ago

Hello @dd32 Thank you for the answer. I agree with you in absolute three is no good reason for disabling the object cache.

But unfortunately I already found 2 plugins that do not work well with object cache :

These plugins are buggy and should be fixed or replaced, but unfortunately it's not always possible quickly, so as a temporary solution I found this filter to disable the object cache for the websites using these plugins on our wp network.

But I agree it's more a hack than a feature, besides without object caching these websites are much more slower :/ Mathieu.