Opened 14 years ago
Last modified 2 years ago
#15565 assigned enhancement
More context for clean_post_cache()
Reported by: | mdawaffe | Owned by: | spacedmonkey |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 3.1 |
Component: | Cache API | Keywords: | dev-feedback needs-refresh has-patch |
Focuses: | Cc: |
Description
I'd like more context to be available when the clean_post_cache hook is run.
Scenario: I have a plugin caches the post_IDs of most post queries that go through WP_Query. Invalidating that cache is done via the clean_post_cache hook, but requires a bunch of fragile hacks to prevent cache invalidation for things like comment inserts, which update the post's comment_count (which could, in theory, affect a WP_Query, but that's another story).
Option 1: Add extra actions to provide context. This is the simpler option. Patch 1 does this for the above scenario.
Option 2: Add an optional context parameter to clean_post_cache(). This is more general, but I can't think of anyplace else WordPress uses as similar approach. Patch two.
Attachments (3)
Change History (19)
#1
@
14 years ago
Option 2 also provides a way to detect if clean_post_cache()
is being run recursively, another case that the scenario I mentioned above has to hack around.
#2
@
14 years ago
We have a $context arg for escaping functions like sanitize_term(), but it's just a string.
#3
@
14 years ago
- Keywords 3.2-early added
- Milestone changed from Awaiting Review to Future Release
Option 2 looks good.
We should add context to all call to clean_post_cache so that a caching plugin can always know what is going on.
#5
@
12 years ago
Note: this would be great for bbPress and anywhere custom post-types are being used creatively. If you invalidate tens of thousands of child-post caches, you're going to have a bad time.
#6
@
12 years ago
I like this in theory. What would all of the contexts look like, for the various uses of clean_post_cache()?
#10
@
11 years ago
- Milestone changed from Future Release to 3.7
This may no longer be a thing since nacin fixed clean_post_cache()
in 3.5, but I refreshed the patch against trunk - let's make a decision on it in 3.7
#11
@
11 years ago
It might still be helpful to include a context for some uses of clean_post_cache(), but it no longer needs to be an array as it is no longer called in recursive fashion.
It seems like the only context you may wish to know is comment_count. Other kinds of cache clears (post and attachment CRUD, set_post_type(), publishing a post) should really not be messed with. Even post reassignments in wp_delete_user() should probably be cleared, though those have the potential to be expensive so that might be the only other situation where context is desired.
#12
@
11 years ago
- Keywords needs-patch added; has-patch removed
- Milestone changed from 3.7 to Future Release
Option 1