Open ericek111 opened 3 years ago
Hello @ericek111
Thank you for taking the time to suggest this and for the pull request you created.
The object cache non-persistent groups can be edited in wp-admin/admin.php?page=w3tc_objectcache The defaults in ConfigKeys.php is only to set the initial default. A user can change the settings at any time. This being said, the devs will make sure to investigate this more we'll get back to you on this. Once again thank you for taking the time to make this suggestion.
Yes, that's what I thought. However, removing the entries from the object cache settings page does not make the groups persistent. The default WP core groups are still merged onto the array (as explained above). I believe this is a bug.
I want to cache counts
. Unless there's some change to either WP core or W3TC, the only way to accomplish that is with hacky access to the nonpersistent_groups
array via reflection.
Thanks for your effort.
WordPress sets the
counts
andplugins
object cache groups as non-persistent early inload.php
using a function defined by the cache provider: https://github.com/W3EDGE/w3-total-cache/blob/88fb395f552133c2afd09c3083dc33334b50c7c4/wp-content/object-cache.php#L153-L157Turns out, with hundreds of thousands of comments, even a simple
COUNT(*)
(insidewp_count_comments
) can cost you 50 - 120 ms on each and every WP admin page.These groups are also specified as defaults in the W3TC config: https://github.com/W3EDGE/w3-total-cache/blob/1e90f05ec230b840f90e8fc63b290871d5a819d9/ConfigKeys.php#L316-L322
And, supposedly, it needn't be persisted: #35430 (Should the 'counts' cache group be persistent?) – WordPress Trac
Removing them from the list of non-persistent groups in admin panel does not help, because that list is only merged on top of the groups provided by WordPress: https://github.com/W3EDGE/w3-total-cache/blob/630001a19be275d0635e168bd1f1f72e57f04fec/ObjectCache_WpObjectCache_Regular.php#L496
My suggestions:
1. Only use the field in W3TC settings. Disregard the
wp_cache_add_non_persistent_groups
call. Those groups are in the ConfigKeys array anyway and they have changed twice in the past 10 years. In fact, they're outdated in the ConfigKeys array (see https://github.com/WordPress/WordPress/commit/a42ce2353a070dc1a42be66c7f7ee8eec606d4df).2. Have some kind of special prefix to remove a group from the default ones. E. g. a minus sign prepended before a group name removes it from the non-persistent groups. So into the text field I add a line with
-counts
to force them to be persisted.