Changeset 21403 for trunk/wp-includes/cache.php
- Timestamp:
- 08/02/2012 06:31:14 PM (13 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/cache.php (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/cache.php
r21294 r21403 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 * … … 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 … … 210 223 * 211 224 * @since 2.6.0 225 * @deprecated 3.5.0 212 226 */ 213 227 function wp_cache_reset() { 228 _deprecated_function( __FUNCTION__, '3.5', 'wp_cache_switch_to_blog()' ); 229 214 230 global $wp_object_cache; 215 231 … … 270 286 */ 271 287 var $global_groups = array(); 288 289 /** 290 * The blog prefix to prepend to keys in non-global groups. 291 * 292 * @var int 293 * @access private 294 * @since 3.5.0 295 */ 296 var $blog_prefix; 272 297 273 298 /** … … 293 318 $group = 'default'; 294 319 295 if ( $this->_exists($key, $group) ) 320 $id = $key; 321 if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) 322 $id = $this->blog_prefix . $key; 323 324 if ( $this->_exists( $id, $group ) ) 296 325 return false; 297 326 … … 309 338 $groups = (array) $groups; 310 339 311 $ this->global_groups = array_merge($this->global_groups, $groups);312 $this->global_groups = array_ unique($this->global_groups);340 $groups = array_fill_keys( $groups, true ); 341 $this->global_groups = array_merge( $this->global_groups, $groups ); 313 342 } 314 343 … … 326 355 if ( empty( $group ) ) 327 356 $group = 'default'; 328 357 358 if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) 359 $key = $this->blog_prefix . $key; 360 329 361 if ( ! $this->_exists( $key, $group ) ) 330 362 return false; … … 362 394 $group = 'default'; 363 395 396 if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) 397 $key = $this->blog_prefix . $key; 398 364 399 if ( ! $force && ! $this->_exists( $key, $group ) ) 365 400 return false; … … 402 437 if ( empty( $group ) ) 403 438 $group = 'default'; 439 440 if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) 441 $key = $this->blog_prefix . $key; 404 442 405 443 if ( $this->_exists( $key, $group ) ) { … … 431 469 $group = 'default'; 432 470 471 if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) 472 $key = $this->blog_prefix . $key; 473 433 474 if ( ! $this->_exists( $key, $group ) ) 434 475 return false; … … 459 500 * @return bool False if not exists, true if contents were replaced 460 501 */ 461 function replace( $key, $data, $group = 'default', $expire = '') {502 function replace( $key, $data, $group = 'default', $expire = '' ) { 462 503 if ( empty( $group ) ) 463 504 $group = 'default'; 464 505 465 if ( ! $this->_exists( $key, $group ) ) 506 $id = $key; 507 if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) 508 $id = $this->blog_prefix . $key; 509 510 if ( ! $this->_exists( $id, $group ) ) 466 511 return false; 467 512 468 return $this->set( $key, $data, $group, $expire);513 return $this->set( $key, $data, $group, $expire ); 469 514 } 470 515 … … 473 518 * 474 519 * @since 3.0.0 520 * @deprecated 3.5.0 475 521 */ 476 522 function reset() { 523 _deprecated_function( __FUNCTION__, '3.5', 'switch_to_blog()' ); 524 477 525 // 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]);526 foreach ( array_keys( $this->cache ) as $group ) { 527 if ( ! isset( $this->global_groups[ $group ] ) ) 528 unset( $this->cache[ $group ] ); 481 529 } 482 530 } … … 506 554 $group = 'default'; 507 555 508 if ( is_object($data) ) 556 if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) 557 $key = $this->blog_prefix . $key; 558 559 if ( is_object( $data ) ) 509 560 $data = clone $data; 510 561 … … 534 585 535 586 /** 587 * Switch the interal blog id. 588 * 589 * This changes the blog id used to create keys in blog specific groups. 590 * 591 * @param int $blog_id Blog ID 592 */ 593 function switch_to_blog( $blog_id ) { 594 $blog_id = (int) $blog_id; 595 $this->blog_prefix = $this->multisite ? $blog_id . ':' : ''; 596 } 597 598 /** 536 599 * Utility function to determine whether a key exists in the cache. 537 600 * … … 551 614 */ 552 615 function __construct() { 616 global $blog_id; 617 618 $this->multisite = is_multisite(); 619 $this->blog_prefix = $this->multisite ? $blog_id . ':' : ''; 620 621 553 622 /** 554 623 * @todo This should be moved to the PHP4 style constructor, PHP5 555 624 * already calls __destruct() 556 625 */ 557 register_shutdown_function( array(&$this, "__destruct"));626 register_shutdown_function( array( &$this, '__destruct' ) ); 558 627 } 559 628
Note: See TracChangeset
for help on using the changeset viewer.