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.



git-svn-id: https://develop.svn.wordpress.org/trunk@25289 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2013-09-06 18:09:24 +00:00
parent 6bad3b660a
commit 22278ec6a9
5 changed files with 41 additions and 35 deletions

View File

@@ -369,6 +369,24 @@ function wp_set_wpdb_vars() {
}
}
/**
* Access/Modify private global variable $_wp_using_ext_object_cache
*
* Toggle $_wp_using_ext_object_cache on and off without directly touching global
*
* @since 3.7.0
*
* @param bool $using Whether external object cache is being used
* @return bool The current 'using' setting
*/
function wp_using_ext_object_cache( $using = null ) {
global $_wp_using_ext_object_cache;
$current_using = $_wp_using_ext_object_cache;
if ( null !== $using )
$_wp_using_ext_object_cache = $using;
return $current_using;
}
/**
* Starts the WordPress object cache.
*
@@ -379,31 +397,33 @@ function wp_set_wpdb_vars() {
* @since 3.0.0
*/
function wp_start_object_cache() {
global $_wp_using_ext_object_cache, $blog_id;
global $blog_id;
$first_init = false;
if ( ! function_exists( 'wp_cache_init' ) ) {
if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
require_once ( WP_CONTENT_DIR . '/object-cache.php' );
$_wp_using_ext_object_cache = true;
} else {
require_once ( ABSPATH . WPINC . '/cache.php' );
$_wp_using_ext_object_cache = false;
if ( function_exists( 'wp_cache_init' ) )
wp_using_ext_object_cache( true );
}
$first_init = true;
} else if ( !$_wp_using_ext_object_cache && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
} else if ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
// Sometimes advanced-cache.php can load object-cache.php before it is loaded here.
// This breaks the function_exists check above and can result in $_wp_using_ext_object_cache
// being set incorrectly. Double check if an external cache exists.
$_wp_using_ext_object_cache = true;
wp_using_ext_object_cache( true );
}
if ( ! wp_using_ext_object_cache() )
require_once ( ABSPATH . WPINC . '/cache.php' );
// If cache supports reset, reset instead of init if already initialized.
// Reset signals to the cache that global IDs have changed and it may need to update keys
// and cleanup caches.
if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) )
wp_cache_switch_to_blog( $blog_id );
else
elseif ( function_exists( 'wp_cache_init' ) )
wp_cache_init();
if ( function_exists( 'wp_cache_add_global_groups' ) ) {