diff --git a/src/wp-includes/ms-blogs.php b/src/wp-includes/ms-blogs.php index 4f0e26085a..50e3358bcc 100644 --- a/src/wp-includes/ms-blogs.php +++ b/src/wp-includes/ms-blogs.php @@ -443,20 +443,28 @@ function update_blog_details( $blog_id, $details = array() ) { * * @since 3.5.0 * + * @global bool $_wp_suspend_cache_invalidation + * * @param WP_Site $blog The site object to be cleared from cache. */ function clean_blog_cache( $blog ) { + global $_wp_suspend_cache_invalidation; + + if ( ! empty( $_wp_suspend_cache_invalidation ) ) { + return; + } + $blog_id = $blog->blog_id; $domain_path_key = md5( $blog->domain . $blog->path ); wp_cache_delete( $blog_id, 'sites' ); wp_cache_delete( $blog_id, 'site-details' ); - wp_cache_delete( $blog_id , 'blog-details' ); + wp_cache_delete( $blog_id, 'blog-details' ); wp_cache_delete( $blog_id . 'short' , 'blog-details' ); - wp_cache_delete( $domain_path_key, 'blog-lookup' ); + wp_cache_delete( $domain_path_key, 'blog-lookup' ); + wp_cache_delete( $domain_path_key, 'blog-id-cache' ); wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' ); wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' ); - wp_cache_delete( $domain_path_key, 'blog-id-cache' ); /** * Fires immediately after a site has been removed from the object cache. @@ -1149,9 +1157,17 @@ function get_network( $network = null ) { * * @since 4.6.0 * + * @global bool $_wp_suspend_cache_invalidation + * * @param int|array $ids Network ID or an array of network IDs to remove from cache. */ function clean_network_cache( $ids ) { + global $_wp_suspend_cache_invalidation; + + if ( ! empty( $_wp_suspend_cache_invalidation ) ) { + return; + } + foreach ( (array) $ids as $id ) { wp_cache_delete( $id, 'networks' ); diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index 7387d95d98..0c8b15f0cc 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -122,6 +122,32 @@ class Tests_Multisite_Site extends WP_UnitTestCase { $this->assertEquals( 2, (int) get_blog_count() ); } + public function test_site_caches_should_invalidate_when_invalidation_is_not_suspended() { + $site_id = self::factory()->blog->create(); + + $details = get_site( $site_id ); + + $suspend = wp_suspend_cache_invalidation( false ); + update_blog_details( $site_id, array( 'path' => '/a-non-random-test-path/' ) ); + $new_details = get_site( $site_id ); + wp_suspend_cache_invalidation( $suspend ); + + $this->assertNotEquals( $details->path, $new_details->path ); + } + + public function test_site_caches_should_not_invalidate_when_invalidation_is_suspended() { + $site_id = self::factory()->blog->create(); + + $details = get_site( $site_id ); + + $suspend = wp_suspend_cache_invalidation(); + update_blog_details( $site_id, array( 'path' => '/a-non-random-test-path/' ) ); + $new_details = get_site( $site_id ); + wp_suspend_cache_invalidation( $suspend ); + + $this->assertEquals( $details->path, $new_details->path ); + } + /** * When a site is flagged as 'deleted', its data should be cleared from cache. */