Ticket #21434: 21434.3.diff
File 21434.3.diff, 8.7 KB (added by , 13 years ago) |
---|
-
wp-includes/load.php
381 381 * @since 3.0.0 382 382 */ 383 383 function wp_start_object_cache() { 384 global $_wp_using_ext_object_cache ;384 global $_wp_using_ext_object_cache, $blog_id; 385 385 386 386 $first_init = false; 387 387 if ( ! function_exists( 'wp_cache_init' ) ) { … … 403 403 // If cache supports reset, reset instead of init if already initialized. 404 404 // Reset signals to the cache that global IDs have changed and it may need to update keys 405 405 // and cleanup caches. 406 if ( ! $first_init && function_exists('wp_cache_reset') )407 wp_cache_ reset();406 if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) 407 wp_cache_switch_to_blog( $blog_id ); 408 408 else 409 409 wp_cache_init(); 410 410 -
wp-includes/ms-blogs.php
487 487 $current_user->for_blog( $blog_id ); 488 488 } 489 489 490 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) 491 $global_groups = $wp_object_cache->global_groups; 492 else 493 $global_groups = false; 494 495 wp_cache_init(); 496 if ( function_exists('wp_cache_add_global_groups') ) { 497 if ( is_array( $global_groups ) ) 498 wp_cache_add_global_groups( $global_groups ); 490 if ( function_exists( 'wp_cache_switch_to_blog' ) ) { 491 wp_cache_switch_to_blog( $blog_id ); 492 } else { 493 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) 494 $global_groups = $wp_object_cache->global_groups; 499 495 else 500 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) ); 501 wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' )); 496 $global_groups = false; 497 498 wp_cache_init(); 499 if ( function_exists('wp_cache_add_global_groups') ) { 500 if ( is_array( $global_groups ) ) 501 wp_cache_add_global_groups( $global_groups ); 502 else 503 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) ); 504 wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' )); 505 } 502 506 } 503 507 504 508 do_action('switch_blog', $blog_id, $prev_blog_id); … … 551 555 $current_user->for_blog( $blog_id ); 552 556 } 553 557 554 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) 555 $global_groups = $wp_object_cache->global_groups; 556 else 557 $global_groups = false; 558 559 wp_cache_init(); 560 if ( function_exists('wp_cache_add_global_groups') ) { 561 if ( is_array( $global_groups ) ) 562 wp_cache_add_global_groups( $global_groups ); 558 if ( function_exists( 'wp_cache_switch_to_blog' ) ) { 559 wp_cache_switch_to_blog( $blog_id ); 560 } else { 561 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) 562 $global_groups = $wp_object_cache->global_groups; 563 563 else 564 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) ); 565 wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' )); 564 $global_groups = false; 565 566 wp_cache_init(); 567 if ( function_exists('wp_cache_add_global_groups') ) { 568 if ( is_array( $global_groups ) ) 569 wp_cache_add_global_groups( $global_groups ); 570 else 571 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) ); 572 wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' )); 573 } 566 574 } 567 575 568 576 do_action('switch_blog', $blog_id, $prev_blog_id); -
wp-includes/cache.php
180 180 } 181 181 182 182 /** 183 * Switch the interal blog id. 184 * 185 * This changes the blog id used to create keys in blog specific groups. 186 * 187 * @param int $blog_id Blog ID 188 */ 189 function wp_cache_switch_to_blog( $blog_id ) { 190 global $wp_object_cache; 191 192 return $wp_object_cache->switch_to_blog( $blog_id ); 193 } 194 195 /** 183 196 * Adds a group or set of groups to the list of global groups. 184 197 * 185 198 * @since 2.6.0 … … 189 202 function wp_cache_add_global_groups( $groups ) { 190 203 global $wp_object_cache; 191 204 192 return $wp_object_cache->add_global_groups( $groups);205 return $wp_object_cache->add_global_groups( $groups ); 193 206 } 194 207 195 208 /** … … 271 284 var $global_groups = array(); 272 285 273 286 /** 287 * The blog prefix to prepend to keys in non-global groups. 288 * 289 * @var int 290 * @access private 291 * @since 3.5.0 292 */ 293 var $blog_prefix; 294 295 /** 274 296 * Adds data to the cache if it doesn't already exist. 275 297 * 276 298 * @uses WP_Object_Cache::_exists Checks to see if the cache already has data. … … 292 314 if ( empty( $group ) ) 293 315 $group = 'default'; 294 316 295 if ( $this->_exists($key, $group) ) 317 $id = $key; 318 if ( $this->multisite && ! in_array( $group, $this->global_groups ) ) 319 $id = $this->blog_prefix . $key; 320 321 if ( $this->_exists( $id, $group ) ) 296 322 return false; 297 323 298 324 return $this->set($key, $data, $group, $expire); … … 325 351 function decr( $key, $offset = 1, $group = 'default' ) { 326 352 if ( empty( $group ) ) 327 353 $group = 'default'; 328 354 355 if ( $this->multisite && ! in_array( $group, $this->global_groups ) ) 356 $key = $this->blog_prefix . $key; 357 329 358 if ( ! $this->_exists( $key, $group ) ) 330 359 return false; 331 360 … … 361 390 if ( empty( $group ) ) 362 391 $group = 'default'; 363 392 393 if ( $this->multisite && ! in_array( $group, $this->global_groups ) ) 394 $key = $this->blog_prefix . $key; 395 364 396 if ( ! $force && ! $this->_exists( $key, $group ) ) 365 397 return false; 366 398 … … 402 434 if ( empty( $group ) ) 403 435 $group = 'default'; 404 436 437 if ( $this->multisite && ! in_array( $group, $this->global_groups ) ) 438 $key = $this->blog_prefix . $key; 439 405 440 if ( $this->_exists( $key, $group ) ) { 406 441 $found = true; 407 442 $this->cache_hits += 1; … … 430 465 if ( empty( $group ) ) 431 466 $group = 'default'; 432 467 468 if ( $this->multisite && ! in_array( $group, $this->global_groups ) ) 469 $key = $this->blog_prefix . $key; 470 433 471 if ( ! $this->_exists( $key, $group ) ) 434 472 return false; 435 473 … … 458 496 * @param int $expire When to expire the cache contents 459 497 * @return bool False if not exists, true if contents were replaced 460 498 */ 461 function replace( $key, $data, $group = 'default', $expire = '') {499 function replace( $key, $data, $group = 'default', $expire = '' ) { 462 500 if ( empty( $group ) ) 463 501 $group = 'default'; 464 502 465 if ( ! $this->_exists( $key, $group ) ) 503 $id = $key; 504 if ( $this->multisite && ! in_array( $group, $this->global_groups ) ) 505 $id = $this->blog_prefix . $key; 506 507 if ( ! $this->_exists( $id, $group ) ) 466 508 return false; 467 509 468 return $this->set( $key, $data, $group, $expire);510 return $this->set( $key, $data, $group, $expire ); 469 511 } 470 512 471 513 /** … … 475 517 */ 476 518 function reset() { 477 519 // Clear out non-global caches since the blog ID has changed. 478 foreach ( array_keys( $this->cache) as $group ) {479 if ( !in_array( $group, $this->global_groups) )480 unset( $this->cache[$group]);520 foreach ( array_keys( $this->cache ) as $group ) { 521 if ( !in_array( $group, $this->global_groups ) ) 522 unset( $this->cache[$group] ); 481 523 } 482 524 } 483 525 … … 505 547 if ( empty( $group ) ) 506 548 $group = 'default'; 507 549 508 if ( is_object($data) ) 550 if ( $this->multisite && ! in_array( $group, $this->global_groups ) ) 551 $key = $this->blog_prefix . $key; 552 553 if ( is_object( $data ) ) 509 554 $data = clone $data; 510 555 511 556 $this->cache[$group][$key] = $data; … … 533 578 } 534 579 535 580 /** 581 * Switch the interal blog id. 582 * 583 * This changes the blog id used to create keys in blog specific groups. 584 * 585 * @param int $blog_id Blog ID 586 */ 587 function switch_to_blog( $blog_id ) { 588 $blog_id = (int) $blog_id; 589 $this->blog_prefix = $this->multisite ? $blog_id . ':' : ''; 590 } 591 592 /** 536 593 * Utility function to determine whether a key exists in the cache. 537 594 * 538 595 * @since 3.4.0 … … 550 607 * @return null|WP_Object_Cache If cache is disabled, returns null. 551 608 */ 552 609 function __construct() { 610 global $blog_id; 611 612 $this->multisite = is_multisite(); 613 $this->blog_prefix = $this->multisite ? $blog_id . ':' : ''; 614 615 553 616 /** 554 617 * @todo This should be moved to the PHP4 style constructor, PHP5 555 618 * already calls __destruct() 556 619 */ 557 register_shutdown_function( array(&$this, "__destruct"));620 register_shutdown_function( array( &$this, "__destruct" ) ); 558 621 } 559 622 560 623 /**