Changeset 18644
- Timestamp:
- 09/06/2011 09:13:11 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/cache.php
r18633 r18644 18 18 * @param int|string $key The cache ID to use for retrieval later 19 19 * @param mixed $data The data to add to the cache store 20 * @param string $ flagThe group to add the cache to20 * @param string $group The group to add the cache to 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, $ flag= '', $expire = 0) {25 global $wp_object_cache; 26 27 return $wp_object_cache->add($key, $data, $ flag, $expire);24 function wp_cache_add($key, $data, $group = '', $expire = 0) { 25 global $wp_object_cache; 26 27 return $wp_object_cache->add($key, $data, $group, $expire); 28 28 } 29 29 … … 53 53 * @param int|string $key The cache ID to increment 54 54 * @param int $offset The amount by which to decrement the item's value. Default is 1. 55 * @param string $ flagThe group the key is in.55 * @param string $group The group the key is in. 56 56 * @return false|int False on failure, the item's new value on success. 57 57 */ 58 function wp_cache_decr( $key, $offset = 1, $ flag= '' ) {59 global $wp_object_cache; 60 61 return $wp_object_cache->decr( $key, $offset, $ flag);58 function wp_cache_decr( $key, $offset = 1, $group = '' ) { 59 global $wp_object_cache; 60 61 return $wp_object_cache->decr( $key, $offset, $group ); 62 62 } 63 63 … … 69 69 * @see WP_Object_Cache::delete() 70 70 * 71 * @param int|string $ idWhat the contents in the cache are called72 * @param string $ flagWhere the cache contents are grouped71 * @param int|string $key What the contents in the cache are called 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($ id, $flag= '') {76 global $wp_object_cache; 77 78 return $wp_object_cache->delete($ id, $flag);75 function wp_cache_delete($key, $group = '') { 76 global $wp_object_cache; 77 78 return $wp_object_cache->delete($key, $group); 79 79 } 80 80 … … 101 101 * @see WP_Object_Cache::get() 102 102 * 103 * @param int|string $ idWhat the contents in the cache are called104 * @param string $ flagWhere the cache contents are grouped103 * @param int|string $key What the contents in the cache are called 104 * @param string $group Where the cache contents are grouped 105 105 * @return bool|mixed False on failure to retrieve contents or the cache 106 106 * contents on success 107 107 */ 108 function wp_cache_get($ id, $flag= '') {109 global $wp_object_cache; 110 111 return $wp_object_cache->get($ id, $flag);108 function wp_cache_get($key, $group = '') { 109 global $wp_object_cache; 110 111 return $wp_object_cache->get($key, $group); 112 112 } 113 113 … … 121 121 * @param int|string $key The cache ID to increment 122 122 * @param int $offset The amount by which to increment the item's value. Default is 1. 123 * @param string $ flagThe group the key is in.123 * @param string $group The group the key is in. 124 124 * @return false|int False on failure, the item's new value on success. 125 125 */ 126 function wp_cache_incr( $key, $offset = 1, $ flag= '' ) {127 global $wp_object_cache; 128 129 return $wp_object_cache->incr( $key, $offset, $ flag);126 function wp_cache_incr( $key, $offset = 1, $group = '' ) { 127 global $wp_object_cache; 128 129 return $wp_object_cache->incr( $key, $offset, $group ); 130 130 } 131 131 … … 149 149 * @param int|string $key What to call the contents in the cache 150 150 * @param mixed $data The contents to store in the cache 151 * @param string $ flagWhere to group the cache contents151 * @param string $group Where to group the cache contents 152 152 * @param int $expire When to expire the cache contents 153 153 * @return bool False if cache ID and group already exists, true on success 154 154 */ 155 function wp_cache_replace($key, $data, $ flag= '', $expire = 0) {156 global $wp_object_cache; 157 158 return $wp_object_cache->replace($key, $data, $ flag, $expire);155 function wp_cache_replace($key, $data, $group = '', $expire = 0) { 156 global $wp_object_cache; 157 158 return $wp_object_cache->replace($key, $data, $group, $expire); 159 159 } 160 160 … … 168 168 * @param int|string $key What to call the contents in the cache 169 169 * @param mixed $data The contents to store in the cache 170 * @param string $ flagWhere to group the cache contents170 * @param string $group Where to group the cache contents 171 171 * @param int $expire When to expire the cache contents 172 172 * @return bool False if cache ID and group already exists, true on success 173 173 */ 174 function wp_cache_set($key, $data, $ flag= '', $expire = 0) {175 global $wp_object_cache; 176 177 return $wp_object_cache->set($key, $data, $ flag, $expire);174 function wp_cache_set($key, $data, $group = '', $expire = 0) { 175 global $wp_object_cache; 176 177 return $wp_object_cache->set($key, $data, $group, $expire); 178 178 } 179 179 … … 287 287 * @since 2.0.0 288 288 * 289 * @param int|string $ idWhat to call the contents in the cache289 * @param int|string $key What to call the contents in the cache 290 290 * @param mixed $data The contents to store in the cache 291 291 * @param string $group Where to group the cache contents … … 293 293 * @return bool False if cache ID and group already exists, true on success 294 294 */ 295 function add( $ id, $data, $group = 'default', $expire = '' ) {295 function add( $key, $data, $group = 'default', $expire = '' ) { 296 296 if ( empty ($group) ) 297 297 $group = 'default'; 298 298 299 if (false !== $this->get($ id, $group))299 if (false !== $this->get($key, $group)) 300 300 return false; 301 301 302 return $this->set($ id, $data, $group, $expire);302 return $this->set($key, $data, $group, $expire); 303 303 } 304 304 … … 322 322 * @since 3.3.0 323 323 * 324 * @param int|string $ idThe cache ID to increment324 * @param int|string $key The cache ID to increment 325 325 * @param int $offset The amount by which to decrement the item's value. Default is 1. 326 * @param string $ flagThe group the key is in.326 * @param string $group The group the key is in. 327 327 * @return false|int False on failure, the item's new value on success. 328 328 */ 329 function decr( $ id, $offset = 1, $group = 'default' ) {330 if ( ! isset( $this->cache[ $group ][ $ id] ) )329 function decr( $key, $offset = 1, $group = 'default' ) { 330 if ( ! isset( $this->cache[ $group ][ $key ] ) ) 331 331 return false; 332 332 333 if ( ! is_numeric( $this->cache[ $group ][ $ id] ) )334 $this->cache[ $group ][ $ id] = 0;333 if ( ! is_numeric( $this->cache[ $group ][ $key ] ) ) 334 $this->cache[ $group ][ $key ] = 0; 335 335 336 336 $offset = (int) $offset; 337 337 338 $this->cache[ $group ][ $ id] -= $offset;339 340 if ( $this->cache[ $group ][ $ id] < 0 )341 $this->cache[ $group ][ $ id] = 0;342 343 return $this->cache[ $group ][ $ id];338 $this->cache[ $group ][ $key ] -= $offset; 339 340 if ( $this->cache[ $group ][ $key ] < 0 ) 341 $this->cache[ $group ][ $key ] = 0; 342 343 return $this->cache[ $group ][ $key ]; 344 344 } 345 345 … … 356 356 * @since 2.0.0 357 357 * 358 * @param int|string $ idWhat the contents in the cache are called358 * @param int|string $key What the contents in the cache are called 359 359 * @param string $group Where the cache contents are grouped 360 360 * @param bool $force Optional. Whether to force the unsetting of the cache … … 362 362 * @return bool False if the contents weren't deleted and true on success 363 363 */ 364 function delete($ id, $group = 'default', $force = false) {364 function delete($key, $group = 'default', $force = false) { 365 365 if (empty ($group)) 366 366 $group = 'default'; 367 367 368 if (!$force && false === $this->get($ id, $group))368 if (!$force && false === $this->get($key, $group)) 369 369 return false; 370 370 371 unset ($this->cache[$group][$ id]);372 $this->non_existent_objects[$group][$ id] = true;371 unset ($this->cache[$group][$key]); 372 $this->non_existent_objects[$group][$key] = true; 373 373 return true; 374 374 } … … 402 402 * @since 2.0.0 403 403 * 404 * @param int|string $ idWhat the contents in the cache are called404 * @param int|string $key What the contents in the cache are called 405 405 * @param string $group Where the cache contents are grouped 406 406 * @return bool|mixed False on failure to retrieve contents or the cache 407 407 * contents on success 408 408 */ 409 function get($ id, $group = 'default') {409 function get($key, $group = 'default') { 410 410 if ( empty ($group) ) 411 411 $group = 'default'; 412 412 413 if ( isset ($this->cache[$group][$ id]) ) {413 if ( isset ($this->cache[$group][$key]) ) { 414 414 $this->cache_hits += 1; 415 if ( is_object($this->cache[$group][$ id]) )416 return clone $this->cache[$group][$ id];415 if ( is_object($this->cache[$group][$key]) ) 416 return clone $this->cache[$group][$key]; 417 417 else 418 return $this->cache[$group][$ id];418 return $this->cache[$group][$key]; 419 419 } 420 420 421 if ( isset ($this->non_existent_objects[$group][$ id]) )421 if ( isset ($this->non_existent_objects[$group][$key]) ) 422 422 return false; 423 423 424 $this->non_existent_objects[$group][$ id] = true;424 $this->non_existent_objects[$group][$key] = true; 425 425 $this->cache_misses += 1; 426 426 return false; … … 432 432 * @since 3.3.0 433 433 * 434 * @param int|string $ idThe cache ID to increment434 * @param int|string $key The cache ID to increment 435 435 * @param int $offset The amount by which to increment the item's value. Default is 1. 436 * @param string $ flagThe group the key is in.436 * @param string $group The group the key is in. 437 437 * @return false|int False on failure, the item's new value on success. 438 438 */ 439 function incr( $ id, $offset = 1, $group = 'default' ) {440 if ( ! isset( $this->cache[ $group ][ $ id] ) )439 function incr( $key, $offset = 1, $group = 'default' ) { 440 if ( ! isset( $this->cache[ $group ][ $key ] ) ) 441 441 return false; 442 442 443 if ( ! is_numeric( $this->cache[ $group ][ $ id] ) )444 $this->cache[ $group ][ $ id] = 0;443 if ( ! is_numeric( $this->cache[ $group ][ $key ] ) ) 444 $this->cache[ $group ][ $key ] = 0; 445 445 446 446 $offset = (int) $offset; 447 447 448 $this->cache[ $group ][ $ id] += $offset;449 450 if ( $this->cache[ $group ][ $ id] < 0 )451 $this->cache[ $group ][ $ id] = 0;452 453 return $this->cache[ $group ][ $ id];448 $this->cache[ $group ][ $key ] += $offset; 449 450 if ( $this->cache[ $group ][ $key ] < 0 ) 451 $this->cache[ $group ][ $key ] = 0; 452 453 return $this->cache[ $group ][ $key ]; 454 454 } 455 455 … … 460 460 * @see WP_Object_Cache::set() 461 461 * 462 * @param int|string $ idWhat to call the contents in the cache462 * @param int|string $key What to call the contents in the cache 463 463 * @param mixed $data The contents to store in the cache 464 464 * @param string $group Where to group the cache contents … … 466 466 * @return bool False if not exists, true if contents were replaced 467 467 */ 468 function replace($ id, $data, $group = 'default', $expire = '') {468 function replace($key, $data, $group = 'default', $expire = '') { 469 469 if (empty ($group)) 470 470 $group = 'default'; 471 471 472 if ( false === $this->get($ id, $group) )472 if ( false === $this->get($key, $group) ) 473 473 return false; 474 474 475 return $this->set($ id, $data, $group, $expire);475 return $this->set($key, $data, $group, $expire); 476 476 } 477 477 … … 493 493 * 494 494 * The cache contents is grouped by the $group parameter followed by the 495 * $ id. This allows for duplicate ids in unique groups. Therefore, naming of495 * $key. This allows for duplicate ids in unique groups. Therefore, naming of 496 496 * the group should be used with care and should follow normal function 497 497 * naming guidelines outside of core WordPress usage. … … 503 503 * @since 2.0.0 504 504 * 505 * @param int|string $ idWhat to call the contents in the cache505 * @param int|string $key What to call the contents in the cache 506 506 * @param mixed $data The contents to store in the cache 507 507 * @param string $group Where to group the cache contents … … 509 509 * @return bool Always returns true 510 510 */ 511 function set($ id, $data, $group = 'default', $expire = '') {511 function set($key, $data, $group = 'default', $expire = '') { 512 512 if ( empty ($group) ) 513 513 $group = 'default'; … … 519 519 $data = clone $data; 520 520 521 $this->cache[$group][$ id] = $data;522 523 if ( isset($this->non_existent_objects[$group][$ id]) )524 unset ($this->non_existent_objects[$group][$ id]);521 $this->cache[$group][$key] = $data; 522 523 if ( isset($this->non_existent_objects[$group][$key]) ) 524 unset ($this->non_existent_objects[$group][$key]); 525 525 526 526 return true;
Note: See TracChangeset
for help on using the changeset viewer.