Make WordPress Core


Ignore:
Timestamp:
09/06/2013 06:09:24 PM (10 years ago)
Author:
wonderboymusic
Message:

Introduce wp_using_ext_object_cache() - mimic wp_suspend_cache_invalidation() and discourage direct access to $_wp_using_ext_object_cache, cleaning up importing of globals in functions and provides function to modify that global. Loads the packaged object cache when an external cache hasn't been loaded or doesn't contain wp_cache_init().

Fixes #21401.

File:
1 edited

Legend:

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

    r24581 r25289  
    371371
    372372/**
     373 * Access/Modify private global variable $_wp_using_ext_object_cache
     374 *
     375 * Toggle $_wp_using_ext_object_cache on and off without directly touching global
     376 *
     377 * @since 3.7.0
     378 *
     379 * @param bool $using Whether external object cache is being used
     380 * @return bool The current 'using' setting
     381 */
     382function wp_using_ext_object_cache( $using = null ) {
     383    global $_wp_using_ext_object_cache;
     384    $current_using = $_wp_using_ext_object_cache;
     385    if ( null !== $using )
     386        $_wp_using_ext_object_cache = $using;
     387    return $current_using;
     388}
     389
     390/**
    373391 * Starts the WordPress object cache.
    374392 *
     
    380398 */
    381399function wp_start_object_cache() {
    382     global $_wp_using_ext_object_cache, $blog_id;
     400    global $blog_id;
    383401
    384402    $first_init = false;
     
    386404        if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
    387405            require_once ( WP_CONTENT_DIR . '/object-cache.php' );
    388             $_wp_using_ext_object_cache = true;
    389         } else {
    390             require_once ( ABSPATH . WPINC . '/cache.php' );
    391             $_wp_using_ext_object_cache = false;
     406            if ( function_exists( 'wp_cache_init' ) )
     407                wp_using_ext_object_cache( true );
    392408        }
     409
    393410        $first_init = true;
    394     } else if ( !$_wp_using_ext_object_cache && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
     411    } else if ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
    395412        // Sometimes advanced-cache.php can load object-cache.php before it is loaded here.
    396413        // This breaks the function_exists check above and can result in $_wp_using_ext_object_cache
    397414        // being set incorrectly. Double check if an external cache exists.
    398         $_wp_using_ext_object_cache = true;
    399     }
     415        wp_using_ext_object_cache( true );
     416    }
     417
     418    if ( ! wp_using_ext_object_cache() )
     419        require_once ( ABSPATH . WPINC . '/cache.php' );
    400420
    401421    // If cache supports reset, reset instead of init if already initialized.
     
    404424    if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) )
    405425        wp_cache_switch_to_blog( $blog_id );
    406     else
     426    elseif ( function_exists( 'wp_cache_init' ) )
    407427        wp_cache_init();
    408428
Note: See TracChangeset for help on using the changeset viewer.