Ticket #21434: 21434.diff
File 21434.diff, 6.2 KB (added by , 13 years ago) |
---|
-
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 … … 292 305 if ( empty( $group ) ) 293 306 $group = 'default'; 294 307 308 $key = $this->key( $id, $group ); 309 295 310 if ( $this->_exists($key, $group) ) 296 311 return false; 297 312 … … 325 340 function decr( $key, $offset = 1, $group = 'default' ) { 326 341 if ( empty( $group ) ) 327 342 $group = 'default'; 328 343 344 $key = $this->key( $id, $group ); 345 329 346 if ( ! $this->_exists( $key, $group ) ) 330 347 return false; 331 348 … … 361 378 if ( empty( $group ) ) 362 379 $group = 'default'; 363 380 381 $key = $this->key( $id, $group ); 382 364 383 if ( ! $force && ! $this->_exists( $key, $group ) ) 365 384 return false; 366 385 … … 402 421 if ( empty( $group ) ) 403 422 $group = 'default'; 404 423 424 $key = $this->key( $id, $group ); 425 405 426 if ( $this->_exists( $key, $group ) ) { 406 427 $found = true; 407 428 $this->cache_hits += 1; … … 430 451 if ( empty( $group ) ) 431 452 $group = 'default'; 432 453 454 $key = $this->key( $id, $group ); 455 433 456 if ( ! $this->_exists( $key, $group ) ) 434 457 return false; 435 458 … … 447 470 } 448 471 449 472 /** 473 * Create a key from a key and group 474 * 475 * @since 3.5.0 476 * 477 * @param string $key A cache key 478 * @param string $group A group 479 * @return string A key for an individual cache bucket 480 */ 481 function key( $key, $group ) { 482 if ( empty( $group ) ) 483 $group = 'default'; 484 485 if ( false !== array_search( $group, $this->global_groups ) ) 486 $prefix = ''; 487 else 488 $prefix = $this->blog_prefix; 489 490 return preg_replace('/\s+/', '', "$prefix$group:$key"); 491 } 492 493 /** 450 494 * Replace the contents in the cache, if contents already exist 451 495 * 452 496 * @since 2.0.0 … … 462 506 if ( empty( $group ) ) 463 507 $group = 'default'; 464 508 509 $key = $this->key( $id, $group ); 510 465 511 if ( ! $this->_exists( $key, $group ) ) 466 512 return false; 467 513 … … 505 551 if ( empty( $group ) ) 506 552 $group = 'default'; 507 553 554 $key = $this->key( $id, $group ); 555 508 556 if ( is_object($data) ) 509 557 $data = clone $data; 510 558 … … 533 581 } 534 582 535 583 /** 584 * Switch the interal blog id. 585 * 586 * This changes the blog id used to create keys in blog specific groups. 587 * 588 * @param int $blog_id Blog ID 589 */ 590 function switch_to_blog( $blog_id ) { 591 $this->blog_prefix = is_multisite() ? get_current_blog_id() . ':' : ''; 592 } 593 594 /** 536 595 * Utility function to determine whether a key exists in the cache. 537 596 * 538 597 * @since 3.4.0 … … 550 609 * @return null|WP_Object_Cache If cache is disabled, returns null. 551 610 */ 552 611 function __construct() { 612 $this->blog_prefix = is_multisite() ? get_current_blog_id() . ':' : ''; 613 553 614 /** 554 615 * @todo This should be moved to the PHP4 style constructor, PHP5 555 616 * already calls __destruct()