Changeset 13066
- Timestamp:
- 02/12/2010 05:06:43 PM (15 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/cache.php
r13054 r13066 150 150 */ 151 151 function wp_cache_add_global_groups( $groups ) { 152 // Default cache doesn't persist so nothing to do here. 153 return; 152 global $wp_object_cache; 153 154 return $wp_object_cache->add_global_groups($groups); 154 155 } 155 156 … … 164 165 // Default cache doesn't persist so nothing to do here. 165 166 return; 167 } 168 169 /** 170 * Reset internal cache keys and structures. If the cache backend uses global blog or site IDs as part of its cache keys, 171 * this function instructs the backend to reset those keys and perform any cleanup since blog or site IDs have changed since cache init. 172 * 173 * @since 2.6.0 174 * 175 * @param string|array $groups A group or an array of groups to add 176 */ 177 function wp_cache_reset() { 178 global $wp_object_cache; 179 180 return $wp_object_cache->reset(); 166 181 } 167 182 … … 219 234 */ 220 235 var $cache_misses = 0; 236 237 /** 238 * List of global groups 239 * 240 * @var array 241 * @access protected 242 * @since 3.0.0 243 */ 244 var $global_groups = array(); 221 245 222 246 /** … … 235 259 * @return bool False if cache ID and group already exists, true on success 236 260 */ 237 function add( $id, $data, $group = 'default', $expire = '') {238 if ( empty ($group))261 function add( $id, $data, $group = 'default', $expire = '' ) { 262 if ( empty ($group) ) 239 263 $group = 'default'; 240 264 … … 243 267 244 268 return $this->set($id, $data, $group, $expire); 269 } 270 271 /** 272 * Sets the list of global groups. 273 * 274 * @since 3.0.0 275 * 276 * @param array $groups List of groups that are global. 277 */ 278 function add_global_groups( $groups ) { 279 $groups = (array) $groups; 280 281 $this->global_groups = array_merge($this->global_groups, $groups); 282 $this->global_groups = array_unique($this->global_groups); 245 283 } 246 284 … … 309 347 */ 310 348 function get($id, $group = 'default') { 311 if ( empty ($group))349 if ( empty ($group) ) 312 350 $group = 'default'; 313 351 314 if ( isset ($this->cache[$group][$id])) {352 if ( isset ($this->cache[$group][$id]) ) { 315 353 $this->cache_hits += 1; 316 354 if ( is_object($this->cache[$group][$id]) ) … … 344 382 $group = 'default'; 345 383 346 if ( false === $this->get($id, $group))384 if ( false === $this->get($id, $group) ) 347 385 return false; 348 386 349 387 return $this->set($id, $data, $group, $expire); 388 } 389 390 /** 391 * Reset keys 392 * 393 * @since 3.0.0 394 */ 395 function reset() { 396 // Clear out non-global caches since the blog ID has changed. 397 foreach ( array_keys($this->cache) as $group ) { 398 if ( !in_array($group, $this->global_groups) ) 399 unset($this->cache[$group]); 400 } 350 401 } 351 402 … … 371 422 */ 372 423 function set($id, $data, $group = 'default', $expire = '') { 373 if ( empty ($group))424 if ( empty ($group) ) 374 425 $group = 'default'; 375 426 376 if ( NULL === $data)427 if ( NULL === $data ) 377 428 $data = ''; 378 429 … … 382 433 $this->cache[$group][$id] = $data; 383 434 384 if (isset($this->non_existent_objects[$group][$id]))435 if ( isset($this->non_existent_objects[$group][$id]) ) 385 436 unset ($this->non_existent_objects[$group][$id]); 386 437 -
trunk/wp-includes/functions.php
r13056 r13066 436 436 437 437 return $alloptions; 438 } 439 440 function wp_load_core_site_options( $site_id = null ) { 441 global $wpdb, $_wp_using_ext_object_cache; 442 443 if ( !is_multisite() || $_wp_using_ext_object_cache || defined( 'WP_INSTALLING' ) ) 444 return; 445 446 if ( empty($site_id) ) 447 $site_id = $wpdb->siteid; 448 449 $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'dashboard_blog'); 450 451 $core_options_in = "'" . implode("', '", $core_options) . "'"; 452 $options = $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $site_id) ); 453 454 foreach ( $options as $option ) { 455 $key = $option->meta_key; 456 $cache_key = "{$site_id}:$key"; 457 $option->meta_value = maybe_unserialize( $option->meta_value ); 458 459 wp_cache_set( $cache_key, $option->meta_value, 'site-options' ); 460 } 438 461 } 439 462 … … 3321 3344 $value = get_option($key, $default); 3322 3345 } else { 3323 $cache_key = "{$wpdb->siteid}:$key"; 3324 3325 if ( $use_cache == true && $value = wp_cache_get($cache_key, 'site-options') ) 3326 return $value; 3327 3328 $value = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $key, $wpdb->siteid) ); 3329 3330 if ( is_null($value) ) 3331 $value = $default; 3332 3333 $value = maybe_unserialize( $value ); 3334 3335 wp_cache_set( $cache_key, $value, 'site-options' ); 3346 $cache_key = "$wpdb->siteid:$key"; 3347 if ( $use_cache ) 3348 $value = wp_cache_get($cache_key, 'site-options'); 3349 3350 if ( false === $value ) { 3351 $value = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $key, $wpdb->siteid) ); 3352 3353 if ( is_null($value) ) 3354 $value = $default; 3355 3356 $value = maybe_unserialize( $value ); 3357 3358 wp_cache_set( $cache_key, $value, 'site-options' ); 3359 } 3336 3360 } 3337 3361 -
trunk/wp-includes/load.php
r13064 r13066 319 319 */ 320 320 function wp_start_object_cache() { 321 if ( ! function_exists( 'wp_cache_init' ) ) { 321 $first_init = false; 322 if ( ! function_exists( 'wp_cache_init' ) ) { 322 323 global $_wp_using_ext_object_cache; 323 324 if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { … … 328 329 $_wp_using_ext_object_cache = false; 329 330 } 330 } 331 332 wp_cache_init(); 331 $first_init = true; 332 } 333 334 // If cache supports reset, reset instead of init if already initialized. 335 // Reset signals to the cache that global IDs have changed and it may need to update keys 336 // and cleanup caches. 337 if ( !$first_init && function_exists('wp_cache_reset') ) 338 wp_cache_reset(); 339 else 340 wp_cache_init(); 341 333 342 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 334 343 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss' ) ); -
trunk/wp-includes/ms-load.php
r13025 r13066 76 76 function get_current_site_name( $current_site ) { 77 77 global $wpdb; 78 $current_site->site_name = wp_cache_get( $current_site->id . ':current_site_name', "site-options");78 $current_site->site_name = wp_cache_get( $current_site->id . ':current_site_name', 'site-options' ); 79 79 if ( ! $current_site->site_name ) { 80 $current_site->site_name = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = %d AND meta_key = 'site_name'", $current_site->id ) ); 81 if ( ! $current_site->site_name ) 82 $current_site->site_name = ucfirst( $current_site->domain ); 80 $current_site->site_name = wp_cache_get( $current_site->id . ':site_name', 'site-options' ); 81 if ( ! $current_site->site_name ) { 82 $current_site->site_name = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = %d AND meta_key = 'site_name'", $current_site->id ) ); 83 if ( ! $current_site->site_name ) 84 $current_site->site_name = ucfirst( $current_site->domain ); 85 } 83 86 wp_cache_set( $current_site->id . ':current_site_name', $current_site->site_name, 'site-options' ); 84 87 } … … 108 111 $current_site->cookie_domain = $current_site->domain; 109 112 113 wp_load_core_site_options($current_site->id); 114 110 115 return $current_site; 111 116 } … … 117 122 $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site 118 123 if ( 1 == count( $sites ) ) { 124 wp_load_core_site_options($current_site->id); 119 125 $current_site = $sites[0]; 120 126 $path = $current_site->path;
Note: See TracChangeset
for help on using the changeset viewer.