0

When I do a wp_cache_set( 'some-item', $item, 'my-group' ) on any site of the multisite network, is some-item available on other blogs, or does every blog have its own "cache domain"?

If cache is local to the current blog only: Is there a simple way to have a shared, network-wide cache?

Could not find anything about this in google or WordPress documentation...

For this question let's assume that there is an object cache plugin or drop-in is installed. (I know that out of the box the wp_cache_set function only caches data for the duration of the current request)

1

It depends.

In general object cache (at least the APCu and memcache based) is global, and is global to the whole server, so the question can be rephrased to "Which caching keys are being prefixed/postfixed with unique strings based on the sub-site". The answer, as can be seen in https://developer.wordpress.org/reference/classes/wp_object_cache/set/ is that wordpress core adds a prefix to "non global groups", where the global groups IIRC are the user data related groups and the network settings group.

So in good object cache implementation, user data and network options cache will be "shared" across all sub-sites while post cache etc will be "locally cached".

This leads to the question of what about the non core my-group. One option is that you will add (or not) prefixes base on the blog id when calculating the cache key to use, or add the my-group as a global group with wp_cache_add_global_groups if you do want to be able to access the same cache info on different sub-sites

  • Excellent answer! Especially the wp_cache_add_global_groups function is new to me... – Philipp May 1 '17 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.