Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Delete Cache by Group #2368
Delete Cache by Group #2368
Changes from 37 commits
8a7dbb4
bdca39b
f87e341
a9b1db9
576d82c
21e6eac
f92ef14
7abf5d6
ee6f101
3d89efd
baa5f32
9305962
63730d5
a9a9e4d
ea41652
095ab96
8dcc405
a7bc773
670e754
fb650ec
2bcc284
c65c89c
c03b962
fcf0c8f
a65bc31
26fcbd8
7d715b7
3f26680
b8c19b0
e890990
a0f699d
47a5b5c
d3ceb58
593dc79
4ecb1de
a26df6d
adac259
1829e23
e76618b
d5e7ed8
5e4433d
63228eb
7f69e33
73fbd0b
156af11
85d09da
f3f143a
3020e38
cd279c0
91a50b8
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a dangerous fallback for this method, having plugin code expecting to flush a specific cache group(s) and then flushing the entire cache is not going to end well.
Additionally, IMHO it's not a
_doing_it_wrong()
E_USER_DEPRECATED
, possibly aE_USER_NOTICE
level warning instead though?(I say this, because with many object caches, it's not possible to flush a specific group, as key-value stores often don't have a "flush keys with this prefix" - Memcache object cache dropin gets around this by prefixing the timestamp to keys, so that it can just switch to a new set of prefixes when flushed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The worry here, is that if you call this function can expect and clear your group and it doesn't we need to warn developer this is happening. Maybe we should return a
WP_Error
object?So you could do this in your own code.
But give devs more control here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the
WP_Error
approach.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
return false
would suffice myself if it wasn't going to flush everything.. "Clear this cache group, sorry, that failed.".But as mentioned in #2368 (comment) variants whose cache server that don't support clearing by prefix, could rotate a prefix to flush the group.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that means that false, could mean a lot of things. Unsupported and the cache group flush failed. That is unclear for developers that using this function, why the failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some feedback from @felixarntz:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felixarntz's comments here reflect statement I have made throughout this code review. These needs to be a way for developers to know if running this function is going to work. They have to know if the object cache implement supports it.
I recommend adding a const, like
WP_CACHE_SUPPORTS_GROUP_FLUSH
, so developers of object cache drop-ins can "opt-in" to support this feature. If this const is not defined, then, developers know not to use this function.See these simplier examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest is using
WP_OBJECTCACHE_*
sinceWP_CACHE
refers to WP's "page caching" mechanism.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a half thought in a Slack thread that I'll leave in full detail here so it doesn't get lost.
For a lot of groups currently, WP uses the
last_changed
cache key to determine when the group was last changed. It acts as a faux group flushing mechanism.wordpress-develop/src/wp-includes/post.php
Line 7406 in 8277055
For drop-ins that support the
flush_group()
method, WP could call that and trust the drop in developer to have checked their persistent cache supports it.For drop-ins that do not include the method, WP could include something similar to polyfill the feature.
At this stage, I'd call this a thought bubble and it absolutely needs further thinking through. One of the issues Dion mentioned in Slack is that there is potential to hit key length issues in some persistent caches.
It's also possible this is a terrible idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the discussion for this ticket should move back to the original tickets. GH is a code review tool and not best designed for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.