Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caching "counts" cache group #114

Closed
maciej-laskowski opened this issue Aug 15, 2019 · 2 comments · Fixed by #345
Closed

Caching "counts" cache group #114

maciej-laskowski opened this issue Aug 15, 2019 · 2 comments · Fixed by #345

Comments

@maciej-laskowski
Copy link

Hi,

I am trying to remove counts from ignored cached groups. I did add
define( 'WP_REDIS_IGNORED_GROUPS', ['plugins'] ); and checked if the constant is being loaded properly and it works. However it turns out that Wordpress runs wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); in wp-includes/load.php on line 586 (https://core.trac.wordpress.org/browser/branches/5.2/src/wp-includes/load.php#L586) which adds counts to ignored groups back regardless of the WP_REDIS_IGNORED_GROUPS setting.

What should I do to enable counts caching? Also, do you have any idea why counts caching is disabled by default? I did study the wp_count_posts() function (https://core.trac.wordpress.org/browser/branches/5.2/src/wp-includes/post.php#L2527) that sets this cache key and it seems to handle all the invalidation etc. so it seems really wasteful to recount posts on every request by default. This was already discussed in #74 but no solution was provided there.

@tillkruss
Copy link
Member

I don’t know why it’s disabled by default.

I also actually ever disabled the counts group. Let me know what you find out when digging into this.

@maciej-laskowski
Copy link
Author

maciej-laskowski commented Aug 16, 2019

The problem is I cannot find a way of enabling counts caching other than commenting out line https://core.trac.wordpress.org/browser/branches/5.2/src/wp-includes/load.php#L586 in WP core which is not a solution. I hoped you might know another way but it seems I should try asking WP core devs about this. Thanks anyway, I will report back if I ever find a solution :)

Issue reported on WP bugtracer https://core.trac.wordpress.org/ticket/47884#ticket

lots0logs added a commit to lots0logs/redis-cache that referenced this issue Apr 4, 2022
Don't allow groups that were manually removed using `WP_REDIS_IGNORED_GROUPS` constant to be added to the ignored groups list.

* FIxes rhubarbgroup#114
* Fixes rhubarbgroup#74
* Ref: https://core.trac.wordpress.org/ticket/47884#ticket
tillkruss pushed a commit that referenced this issue Aug 11, 2022
* Update add_non_persistent_groups()

Don't allow groups that were manually removed using `WP_REDIS_IGNORED_GROUPS` constant to be added to the ignored groups list.

* FIxes #114
* Fixes #74
* Ref: https://core.trac.wordpress.org/ticket/47884#ticket

* Fix error in logic

* Incorporate pr review feedback

* improved implementation

* fix typo

* Added new filter: redis_add_non_persistent_groups

This makes it possible to override the default ignored groups set by WordPress core without any complex, hard to follow logic attempting to filter out the default groups only when they were removed using `WP_REDIS_IGNORED_GROUPS` constant.

* update filter name to use existing naming scheme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants