WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 14 months ago

#23290 new defect (bug)

When using switch_to_blog() with a persistent object cache that lacks wp_cache_switch_to_blog() support, non-persistent groups are not maintained

Reported by: markjaquith Owned by:
Milestone: Future Release Priority: low
Severity: normal Version: 3.0
Component: Cache API Keywords: has-patch needs-testing needs-unit-tests
Focuses: multisite Cc:

Description

If you're using a persistent object cache that lacks the new wp_cache_switch_to_blog() support, WordPress core elses into a complete cache clobbering branch. It is smart about grabbing the global groups and re-adding those after wp_cache_init() is called, but it doesn't do the same for non-persistent groups. Those are a hardcoded array. So if you call switch_to_blog(), you would lose any custom-added non-persistent groups.

Attachments (1)

23290.patch (4.6 KB) - added by ethitter 2 years ago.

Download all attachments as: .zip

Change History (16)

comment:1 @johnjamesjacoby2 years ago

  • Cc johnjamesjacoby added

comment:2 @nacin2 years ago

  • Version set to 3.0

Curiously, not a regression — existed back when this was just a wp_cache_init() call too.

comment:3 @ethitter2 years ago

  • Cc erick@… added

comment:4 @stevenkword2 years ago

  • Cc stevenword@… added

@ethitter2 years ago

comment:5 @ethitter2 years ago

  • Keywords has-patch needs-testing added

@stevenkword and I worked on 23290.patch during the Boston WP Hack Day.

We introduced a get_non_persistent_groups() method in Core's WP_Object_Cache to handle the core use, and to be implemented by authors of object cache drop ins. Initially we tried to include universal support for getting the non-persistent cache groups, but review of the APC Object Caching plugin revealed that the structure of $global_groups can vary between persistent backends.

The switching fallback that was present in switch_to_blog() and restore_current_blog() was abstracted into _ms_cache_switch_fallback() for consistency, and logic to use the persistent group getter closely mirrors the handling of global groups already in those functions.

comment:6 @nacin23 months ago

  • Keywords 3.7-early added
  • Milestone changed from 3.6 to Future Release

I like this; let's address it in 3.7.

comment:7 @wonderboymusic22 months ago

  • Milestone changed from Future Release to 3.7

these are all marked 3.7-early

comment:8 @nacin20 months ago

  • Keywords 3.7-early removed
  • Milestone changed from 3.7 to 3.8

Let's make sure ryan looks this over.

comment:9 @wonderboymusic18 months ago

  • Keywords needs-unit-tests added

comment:10 @nunomorgadinho18 months ago

Any suggestions on what a unit test for this one should include? Maybe we could even separate it into different unit tests. I'm unsure and would appreciate feedback as I would be interested in working on it.

Last edited 18 months ago by nunomorgadinho (previous) (diff)

comment:11 @nunomorgadinho18 months ago

  • Cc nuno.morgadinho@… added

comment:12 @wonderboymusic18 months ago

  • Milestone changed from 3.8 to Future Release

No unit tests - no Ryan blessing

comment:13 @jeremyfelt16 months ago

  • Focuses multisite added
  • Milestone changed from Future Release to 3.9

We probably have an opportunity to get some unit tests in for this in 3.9.

@nunomorgadinho, if you are still interested in working on this, please feel free. It's probably worth looking at the current code in phpunit/tests/cache.php for examples of testing switch_to_blog(). We would then want to use additional tests for the pieces that this patch touches. Don't hesitate to provide any first attempts or stop in #wordpress-dev to go over approach.

comment:14 @jeremyfelt14 months ago

This is probably going to miss 3.9 unless we can get some testing and tests in here.

comment:15 @nacin14 months ago

  • Milestone changed from 3.9 to Future Release
  • Priority changed from normal to low

There are a number of Cache API things we'd like to do, so moving this out of 3.9.

It's much, much better for object caches to introduce wp_cache_switch_to_blog(), so this is fairly low priority.

Note: See TracTickets for help on using tickets.