Ticket #21434: 21434.2.diff
File 21434.2.diff, 7.9 KB (added by , 12 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 … … 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 = $this->key( $key, $group ); 318 319 if ( $this->_exists( $id, $group ) ) 296 320 return false; 297 321 298 322 return $this->set($key, $data, $group, $expire); … … 325 349 function decr( $key, $offset = 1, $group = 'default' ) { 326 350 if ( empty( $group ) ) 327 351 $group = 'default'; 328 352 353 $key = $this->key( $key, $group ); 354 329 355 if ( ! $this->_exists( $key, $group ) ) 330 356 return false; 331 357 … … 361 387 if ( empty( $group ) ) 362 388 $group = 'default'; 363 389 390 $key = $this->key( $key, $group ); 391 364 392 if ( ! $force && ! $this->_exists( $key, $group ) ) 365 393 return false; 366 394 … … 402 430 if ( empty( $group ) ) 403 431 $group = 'default'; 404 432 433 $key = $this->key( $key, $group ); 434 405 435 if ( $this->_exists( $key, $group ) ) { 406 436 $found = true; 407 437 $this->cache_hits += 1; … … 430 460 if ( empty( $group ) ) 431 461 $group = 'default'; 432 462 463 $key = $this->key( $key, $group ); 464 433 465 if ( ! $this->_exists( $key, $group ) ) 434 466 return false; 435 467 … … 447 479 } 448 480 449 481 /** 482 * Create a key from a key and group 483 * 484 * @since 3.5.0 485 * 486 * @param string $key A cache key 487 * @param string $group A group 488 * @return string A key for an individual cache bucket 489 */ 490 function key( $key, $group ) { 491 if ( empty( $group ) ) 492 $group = 'default'; 493 494 if ( false !== array_search( $group, $this->global_groups ) ) 495 $prefix = ''; 496 else 497 $prefix = $this->blog_prefix; 498 499 return "$prefix$key"; 500 } 501 502 /** 450 503 * Replace the contents in the cache, if contents already exist 451 504 * 452 505 * @since 2.0.0 … … 458 511 * @param int $expire When to expire the cache contents 459 512 * @return bool False if not exists, true if contents were replaced 460 513 */ 461 function replace( $key, $data, $group = 'default', $expire = '') {514 function replace( $key, $data, $group = 'default', $expire = '' ) { 462 515 if ( empty( $group ) ) 463 516 $group = 'default'; 464 517 465 if ( ! $this->_exists( $key, $group ) ) 518 $id = $this->key( $key, $group ); 519 520 if ( ! $this->_exists( $id, $group ) ) 466 521 return false; 467 522 468 return $this->set( $key, $data, $group, $expire);523 return $this->set( $key, $data, $group, $expire ); 469 524 } 470 525 471 526 /** … … 475 530 */ 476 531 function reset() { 477 532 // 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]);533 foreach ( array_keys( $this->cache ) as $group ) { 534 if ( !in_array( $group, $this->global_groups ) ) 535 unset( $this->cache[$group] ); 481 536 } 482 537 } 483 538 … … 505 560 if ( empty( $group ) ) 506 561 $group = 'default'; 507 562 508 if ( is_object($data) ) 563 $key = $this->key( $key, $group ); 564 565 if ( is_object( $data ) ) 509 566 $data = clone $data; 510 567 511 568 $this->cache[$group][$key] = $data; … … 533 590 } 534 591 535 592 /** 593 * Switch the interal blog id. 594 * 595 * This changes the blog id used to create keys in blog specific groups. 596 * 597 * @param int $blog_id Blog ID 598 */ 599 function switch_to_blog( $blog_id ) { 600 $blog_id = (int) $blog_id; 601 $this->blog_prefix = is_multisite() ? $blog_id . ':' : ''; 602 } 603 604 /** 536 605 * Utility function to determine whether a key exists in the cache. 537 606 * 538 607 * @since 3.4.0 … … 550 619 * @return null|WP_Object_Cache If cache is disabled, returns null. 551 620 */ 552 621 function __construct() { 622 global $blog_id; 623 624 $this->blog_prefix = is_multisite() ? $blog_id . ':' : ''; 625 553 626 /** 554 627 * @todo This should be moved to the PHP4 style constructor, PHP5 555 628 * already calls __destruct() 556 629 */ 557 register_shutdown_function( array(&$this, "__destruct"));630 register_shutdown_function( array( &$this, "__destruct" ) ); 558 631 } 559 632 560 633 /**