Multisite: Respect `$_wp_suspend_cache_invalidation` when clearing network and site caches.
Props johnjamesjacoby. Fixes #40028. git-svn-id: https://develop.svn.wordpress.org/trunk@40346 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
83002e564e
commit
6790fcb55d
|
@ -443,20 +443,28 @@ function update_blog_details( $blog_id, $details = array() ) {
|
||||||
*
|
*
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*
|
*
|
||||||
|
* @global bool $_wp_suspend_cache_invalidation
|
||||||
|
*
|
||||||
* @param WP_Site $blog The site object to be cleared from cache.
|
* @param WP_Site $blog The site object to be cleared from cache.
|
||||||
*/
|
*/
|
||||||
function clean_blog_cache( $blog ) {
|
function clean_blog_cache( $blog ) {
|
||||||
|
global $_wp_suspend_cache_invalidation;
|
||||||
|
|
||||||
|
if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$blog_id = $blog->blog_id;
|
$blog_id = $blog->blog_id;
|
||||||
$domain_path_key = md5( $blog->domain . $blog->path );
|
$domain_path_key = md5( $blog->domain . $blog->path );
|
||||||
|
|
||||||
wp_cache_delete( $blog_id, 'sites' );
|
wp_cache_delete( $blog_id, 'sites' );
|
||||||
wp_cache_delete( $blog_id, 'site-details' );
|
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( $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, 'site-options' );
|
||||||
wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, '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.
|
* 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
|
* @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.
|
* @param int|array $ids Network ID or an array of network IDs to remove from cache.
|
||||||
*/
|
*/
|
||||||
function clean_network_cache( $ids ) {
|
function clean_network_cache( $ids ) {
|
||||||
|
global $_wp_suspend_cache_invalidation;
|
||||||
|
|
||||||
|
if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ( (array) $ids as $id ) {
|
foreach ( (array) $ids as $id ) {
|
||||||
wp_cache_delete( $id, 'networks' );
|
wp_cache_delete( $id, 'networks' );
|
||||||
|
|
||||||
|
|
|
@ -122,6 +122,32 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
|
||||||
$this->assertEquals( 2, (int) get_blog_count() );
|
$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.
|
* When a site is flagged as 'deleted', its data should be cleared from cache.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue