Make WordPress Core

Changeset 40346


Ignore:
Timestamp:
03/28/2017 07:35:49 PM (6 years ago)
Author:
jeremyfelt
Message:

Multisite: Respect $_wp_suspend_cache_invalidation when clearing network and site caches.

Props johnjamesjacoby.
Fixes #40028.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-blogs.php

    r40340 r40346  
    444444 * @since 3.5.0
    445445 *
     446 * @global bool $_wp_suspend_cache_invalidation
     447 *
    446448 * @param WP_Site $blog The site object to be cleared from cache.
    447449 */
    448450function clean_blog_cache( $blog ) {
     451    global $_wp_suspend_cache_invalidation;
     452
     453    if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
     454        return;
     455    }
     456
    449457    $blog_id = $blog->blog_id;
    450458    $domain_path_key = md5( $blog->domain . $blog->path );
     
    452460    wp_cache_delete( $blog_id, 'sites' );
    453461    wp_cache_delete( $blog_id, 'site-details' );
    454     wp_cache_delete( $blog_id , 'blog-details' );
     462    wp_cache_delete( $blog_id, 'blog-details' );
    455463    wp_cache_delete( $blog_id . 'short' , 'blog-details' );
    456     wp_cache_delete(  $domain_path_key, 'blog-lookup' );
     464    wp_cache_delete( $domain_path_key, 'blog-lookup' );
     465    wp_cache_delete( $domain_path_key, 'blog-id-cache' );
    457466    wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' );
    458467    wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' );
    459     wp_cache_delete( $domain_path_key, 'blog-id-cache' );
    460468
    461469    /**
     
    11501158 * @since 4.6.0
    11511159 *
     1160 * @global bool $_wp_suspend_cache_invalidation
     1161 *
    11521162 * @param int|array $ids Network ID or an array of network IDs to remove from cache.
    11531163 */
    11541164function clean_network_cache( $ids ) {
     1165    global $_wp_suspend_cache_invalidation;
     1166
     1167    if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
     1168        return;
     1169    }
     1170
    11551171    foreach ( (array) $ids as $id ) {
    11561172        wp_cache_delete( $id, 'networks' );
  • trunk/tests/phpunit/tests/multisite/site.php

    r39173 r40346  
    121121        wp_update_network_counts();
    122122        $this->assertEquals( 2, (int) get_blog_count() );
     123    }
     124
     125    public function test_site_caches_should_invalidate_when_invalidation_is_not_suspended() {
     126        $site_id = self::factory()->blog->create();
     127
     128        $details = get_site( $site_id );
     129
     130        $suspend = wp_suspend_cache_invalidation( false );
     131        update_blog_details( $site_id, array( 'path' => '/a-non-random-test-path/' ) );
     132        $new_details = get_site( $site_id );
     133        wp_suspend_cache_invalidation( $suspend );
     134
     135        $this->assertNotEquals( $details->path, $new_details->path );
     136    }
     137
     138    public function test_site_caches_should_not_invalidate_when_invalidation_is_suspended() {
     139        $site_id = self::factory()->blog->create();
     140
     141        $details = get_site( $site_id );
     142
     143        $suspend = wp_suspend_cache_invalidation();
     144        update_blog_details( $site_id, array( 'path' => '/a-non-random-test-path/' ) );
     145        $new_details = get_site( $site_id );
     146        wp_suspend_cache_invalidation( $suspend );
     147
     148        $this->assertEquals( $details->path, $new_details->path );
    123149    }
    124150
Note: See TracChangeset for help on using the changeset viewer.