Ticket #21402: format-cache.diff
File format-cache.diff, 6.5 KB (added by , 11 years ago) |
---|
-
wp-includes/cache.php
21 21 * @param int $expire When the cache data should be expired 22 22 * @return unknown 23 23 */ 24 function wp_cache_add( $key, $data, $group = '', $expire = 0) {24 function wp_cache_add( $key, $data, $group = '', $expire = 0 ) { 25 25 global $wp_object_cache; 26 26 27 return $wp_object_cache->add( $key, $data, $group, $expire);27 return $wp_object_cache->add( $key, $data, $group, $expire ); 28 28 } 29 29 30 30 /** … … 72 72 * @param string $group Where the cache contents are grouped 73 73 * @return bool True on successful removal, false on failure 74 74 */ 75 function wp_cache_delete( $key, $group = '') {75 function wp_cache_delete( $key, $group = '' ) { 76 76 global $wp_object_cache; 77 77 78 return $wp_object_cache->delete( $key, $group);78 return $wp_object_cache->delete( $key, $group ); 79 79 } 80 80 81 81 /** … … 154 154 * @param int $expire When to expire the cache contents 155 155 * @return bool False if cache key and group already exist, true on success 156 156 */ 157 function wp_cache_replace( $key, $data, $group = '', $expire = 0) {157 function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) { 158 158 global $wp_object_cache; 159 159 160 return $wp_object_cache->replace( $key, $data, $group, $expire);160 return $wp_object_cache->replace( $key, $data, $group, $expire ); 161 161 } 162 162 163 163 /** … … 173 173 * @param int $expire When to expire the cache contents 174 174 * @return bool False if cache key and group already exist, true on success 175 175 */ 176 function wp_cache_set( $key, $data, $group = '', $expire = 0) {176 function wp_cache_set( $key, $data, $group = '', $expire = 0 ) { 177 177 global $wp_object_cache; 178 178 179 return $wp_object_cache->set( $key, $data, $group, $expire);179 return $wp_object_cache->set( $key, $data, $group, $expire ); 180 180 } 181 181 182 182 /** … … 189 189 function wp_cache_add_global_groups( $groups ) { 190 190 global $wp_object_cache; 191 191 192 return $wp_object_cache->add_global_groups( $groups);192 return $wp_object_cache->add_global_groups( $groups ); 193 193 } 194 194 195 195 /** … … 241 241 * @access private 242 242 * @since 2.0.0 243 243 */ 244 var $cache = array 244 var $cache = array(); 245 245 246 246 /** 247 247 * The amount of times the cache data was already stored in the cache. … … 292 292 if ( empty( $group ) ) 293 293 $group = 'default'; 294 294 295 if ( $this->_exists( $key, $group) )295 if ( $this->_exists( $key, $group ) ) 296 296 return false; 297 297 298 return $this->set( $key, $data, $group, $expire);298 return $this->set( $key, $data, $group, $expire ); 299 299 } 300 300 301 301 /** … … 308 308 function add_global_groups( $groups ) { 309 309 $groups = (array) $groups; 310 310 311 $this->global_groups = array_merge( $this->global_groups, $groups);312 $this->global_groups = array_unique( $this->global_groups);311 $this->global_groups = array_merge( $this->global_groups, $groups ); 312 $this->global_groups = array_unique( $this->global_groups ); 313 313 } 314 314 315 315 /** … … 357 357 * key in the group 358 358 * @return bool False if the contents weren't deleted and true on success 359 359 */ 360 function delete( $key, $group = 'default', $force = false) {360 function delete( $key, $group = 'default', $force = false ) { 361 361 if ( empty( $group ) ) 362 362 $group = 'default'; 363 363 364 364 if ( ! $force && ! $this->_exists( $key, $group ) ) 365 365 return false; 366 366 367 unset( $this->cache[ $group][$key] );367 unset( $this->cache[ $group ][ $key ] ); 368 368 return true; 369 369 } 370 370 … … 376 376 * @return bool Always returns true 377 377 */ 378 378 function flush() { 379 $this->cache = array 379 $this->cache = array(); 380 380 381 381 return true; 382 382 } … … 405 405 if ( $this->_exists( $key, $group ) ) { 406 406 $found = true; 407 407 $this->cache_hits += 1; 408 if ( is_object( $this->cache[$group][$key]) )409 return clone $this->cache[ $group][$key];408 if ( is_object( $this->cache[ $group ][ $key ] ) ) 409 return clone $this->cache[ $group ][ $key ]; 410 410 else 411 return $this->cache[ $group][$key];411 return $this->cache[ $group ][ $key ]; 412 412 } 413 413 414 414 $found = false; … … 458 458 * @param int $expire When to expire the cache contents 459 459 * @return bool False if not exists, true if contents were replaced 460 460 */ 461 function replace( $key, $data, $group = 'default', $expire = '') {461 function replace( $key, $data, $group = 'default', $expire = '' ) { 462 462 if ( empty( $group ) ) 463 463 $group = 'default'; 464 464 465 465 if ( ! $this->_exists( $key, $group ) ) 466 466 return false; 467 467 468 return $this->set( $key, $data, $group, $expire);468 return $this->set( $key, $data, $group, $expire ); 469 469 } 470 470 471 471 /** … … 475 475 */ 476 476 function reset() { 477 477 // 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]);478 foreach ( array_keys( $this->cache ) as $group ) { 479 if ( !in_array( $group, $this->global_groups ) ) 480 unset( $this->cache[ $group ] ); 481 481 } 482 482 } 483 483 … … 501 501 * @param int $expire Not Used 502 502 * @return bool Always returns true 503 503 */ 504 function set( $key, $data, $group = 'default', $expire = '') {504 function set( $key, $data, $group = 'default', $expire = '' ) { 505 505 if ( empty( $group ) ) 506 506 $group = 'default'; 507 507 508 if ( is_object( $data) )508 if ( is_object( $data ) ) 509 509 $data = clone $data; 510 510 511 $this->cache[ $group][$key] = $data;511 $this->cache[ $group ][ $key ] = $data; 512 512 return true; 513 513 } 514 514 … … 526 526 echo "<strong>Cache Misses:</strong> {$this->cache_misses}<br />"; 527 527 echo "</p>"; 528 528 echo '<ul>'; 529 foreach ( $this->cache as $group => $cache) {529 foreach ( $this->cache as $group => $cache ) { 530 530 echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / 1024, 2 ) . 'k )</li>'; 531 531 } 532 532 echo '</ul>'; … … 542 542 protected function _exists( $key, $group ) { 543 543 return isset( $this->cache[ $group ] ) && ( isset( $this->cache[ $group ][ $key ] ) || array_key_exists( $key, $this->cache[ $group ] ) ); 544 544 } 545 546 /**547 * Sets up object properties; PHP 5 style constructor548 *549 * @since 2.0.8550 * @return null|WP_Object_Cache If cache is disabled, returns null.551 */552 function __construct() {553 /**554 * @todo This should be moved to the PHP4 style constructor, PHP5555 * already calls __destruct()556 */557 register_shutdown_function(array(&$this, "__destruct"));558 }559 560 /**561 * Will save the object cache before object is completely destroyed.562 *563 * Called upon object destruction, which should be when PHP ends.564 *565 * @since 2.0.8566 *567 * @return bool True value. Won't be used by PHP568 */569 function __destruct() {570 return true;571 }572 545 }