Make WordPress Core

Opened 13 years ago

Last modified 11 months ago

#15565 assigned enhancement

More context for clean_post_cache()

Reported by: mdawaffe's profile mdawaffe Owned by: spacedmonkey's profile spacedmonkey
Milestone: Future Release Priority: normal
Severity: normal Version: 3.1
Component: Cache API Keywords: dev-feedback needs-refresh has-patch
Focuses: Cc:


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)

15565.1.diff (597 bytes) - added by mdawaffe 13 years ago.
Option 1
15565.2.diff (2.3 KB) - added by mdawaffe 13 years ago.
Option 2
15565.diff (1.7 KB) - added by wonderboymusic 10 years ago.

Download all attachments as: .zip

Change History (19)

13 years ago

Option 1

13 years ago

Option 2

#1 @mdawaffe
13 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 @scribu
13 years ago

We have a $context arg for escaping functions like sanitize_term(), but it's just a string.

#3 @westi
13 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.

#4 @batmoo
11 years ago

  • Cc batmoo@… added

#5 @johnjamesjacoby
11 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 @nacin
11 years ago

I like this in theory. What would all of the contexts look like, for the various uses of clean_post_cache()?

#7 @nacin
11 years ago

  • Type changed from feature request to enhancement

#8 @jkudish
11 years ago

related: #11399

#9 @ryan
11 years ago

Related: #22176

#10 @wonderboymusic
10 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 @nacin
10 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 @nacin
10 years ago

  • Keywords needs-patch added; has-patch removed
  • Milestone changed from 3.7 to Future Release

#13 @chriscct7
8 years ago

  • Keywords dev-feedback added; 3.2-early removed

#14 @desrosj
11 months ago

  • Keywords needs-refresh has-patch added; needs-patch removed
  • Milestone set to Future Release

Re-adding a milestone to this one.

You've been focusing a lot on the Cache API lately, @spacedmonkey. Is this something you'd be interested in exploring?

#15 @spacedmonkey
11 months ago

  • Owner set to spacedmonkey
  • Status changed from new to assigned

#16 @spacedmonkey
11 months ago

This is heavily related to #22176. So I will take ownership of this.

Note: See TracTickets for help on using tickets.