WordPress.org

Make WordPress Core

Changeset 18644


Ignore:
Timestamp:
09/06/11 21:13:11 (3 years ago)
Author:
ryan
Message:

Standardize variable names. Consistently use and . fixes #18607

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/cache.php

    r18633 r18644  
    1818 * @param int|string $key The cache ID to use for retrieval later 
    1919 * @param mixed $data The data to add to the cache store 
    20  * @param string $flag The group to add the cache to 
     20 * @param string $group The group to add the cache to 
    2121 * @param int $expire When the cache data should be expired 
    2222 * @return unknown 
    2323 */ 
    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); 
     24function wp_cache_add($key, $data, $group = '', $expire = 0) { 
     25    global $wp_object_cache; 
     26 
     27    return $wp_object_cache->add($key, $data, $group, $expire); 
    2828} 
    2929 
     
    5353 * @param int|string $key The cache ID to increment 
    5454 * @param int $offset The amount by which to decrement the item's value.  Default is 1. 
    55  * @param string $flag The group the key is in. 
     55 * @param string $group The group the key is in. 
    5656 * @return false|int False on failure, the item's new value on success. 
    5757 */ 
    58 function wp_cache_decr( $key, $offset = 1, $flag = '' ) { 
    59     global $wp_object_cache; 
    60  
    61     return $wp_object_cache->decr( $key, $offset, $flag ); 
     58function wp_cache_decr( $key, $offset = 1, $group = '' ) { 
     59    global $wp_object_cache; 
     60 
     61    return $wp_object_cache->decr( $key, $offset, $group ); 
    6262} 
    6363 
     
    6969 * @see WP_Object_Cache::delete() 
    7070 * 
    71  * @param int|string $id What the contents in the cache are called 
    72  * @param string $flag Where the cache contents are grouped 
     71 * @param int|string $key What the contents in the cache are called 
     72 * @param string $group Where the cache contents are grouped 
    7373 * @return bool True on successful removal, false on failure 
    7474 */ 
    75 function wp_cache_delete($id, $flag = '') { 
    76     global $wp_object_cache; 
    77  
    78     return $wp_object_cache->delete($id, $flag); 
     75function wp_cache_delete($key, $group = '') { 
     76    global $wp_object_cache; 
     77 
     78    return $wp_object_cache->delete($key, $group); 
    7979} 
    8080 
     
    101101 * @see WP_Object_Cache::get() 
    102102 * 
    103  * @param int|string $id What the contents in the cache are called 
    104  * @param string $flag Where the cache contents are grouped 
     103 * @param int|string $key What the contents in the cache are called 
     104 * @param string $group Where the cache contents are grouped 
    105105 * @return bool|mixed False on failure to retrieve contents or the cache 
    106106 *      contents on success 
    107107 */ 
    108 function wp_cache_get($id, $flag = '') { 
    109     global $wp_object_cache; 
    110  
    111     return $wp_object_cache->get($id, $flag); 
     108function wp_cache_get($key, $group = '') { 
     109    global $wp_object_cache; 
     110 
     111    return $wp_object_cache->get($key, $group); 
    112112} 
    113113 
     
    121121 * @param int|string $key The cache ID to increment 
    122122 * @param int $offset The amount by which to increment the item's value.  Default is 1. 
    123  * @param string $flag The group the key is in. 
     123 * @param string $group The group the key is in. 
    124124 * @return false|int False on failure, the item's new value on success. 
    125125 */ 
    126 function wp_cache_incr( $key, $offset = 1, $flag = '' ) { 
    127     global $wp_object_cache; 
    128  
    129     return $wp_object_cache->incr( $key, $offset, $flag ); 
     126function wp_cache_incr( $key, $offset = 1, $group = '' ) { 
     127    global $wp_object_cache; 
     128 
     129    return $wp_object_cache->incr( $key, $offset, $group ); 
    130130} 
    131131 
     
    149149 * @param int|string $key What to call the contents in the cache 
    150150 * @param mixed $data The contents to store in the cache 
    151  * @param string $flag Where to group the cache contents 
     151 * @param string $group Where to group the cache contents 
    152152 * @param int $expire When to expire the cache contents 
    153153 * @return bool False if cache ID and group already exists, true on success 
    154154 */ 
    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); 
     155function wp_cache_replace($key, $data, $group = '', $expire = 0) { 
     156    global $wp_object_cache; 
     157 
     158    return $wp_object_cache->replace($key, $data, $group, $expire); 
    159159} 
    160160 
     
    168168 * @param int|string $key What to call the contents in the cache 
    169169 * @param mixed $data The contents to store in the cache 
    170  * @param string $flag Where to group the cache contents 
     170 * @param string $group Where to group the cache contents 
    171171 * @param int $expire When to expire the cache contents 
    172172 * @return bool False if cache ID and group already exists, true on success 
    173173 */ 
    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); 
     174function wp_cache_set($key, $data, $group = '', $expire = 0) { 
     175    global $wp_object_cache; 
     176 
     177    return $wp_object_cache->set($key, $data, $group, $expire); 
    178178} 
    179179 
     
    287287     * @since 2.0.0 
    288288     * 
    289      * @param int|string $id What to call the contents in the cache 
     289     * @param int|string $key What to call the contents in the cache 
    290290     * @param mixed $data The contents to store in the cache 
    291291     * @param string $group Where to group the cache contents 
     
    293293     * @return bool False if cache ID and group already exists, true on success 
    294294     */ 
    295     function add( $id, $data, $group = 'default', $expire = '' ) { 
     295    function add( $key, $data, $group = 'default', $expire = '' ) { 
    296296        if ( empty ($group) ) 
    297297            $group = 'default'; 
    298298 
    299         if (false !== $this->get($id, $group)) 
     299        if (false !== $this->get($key, $group)) 
    300300            return false; 
    301301 
    302         return $this->set($id, $data, $group, $expire); 
     302        return $this->set($key, $data, $group, $expire); 
    303303    } 
    304304 
     
    322322     * @since 3.3.0 
    323323     * 
    324      * @param int|string $id The cache ID to increment 
     324     * @param int|string $key The cache ID to increment 
    325325     * @param int $offset The amount by which to decrement the item's value.  Default is 1. 
    326      * @param string $flag The group the key is in. 
     326     * @param string $group The group the key is in. 
    327327     * @return false|int False on failure, the item's new value on success. 
    328328     */ 
    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 ] ) ) 
    331331            return false; 
    332332 
    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; 
    335335 
    336336        $offset = (int) $offset; 
    337337 
    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 ]; 
    344344    } 
    345345 
     
    356356     * @since 2.0.0 
    357357     * 
    358      * @param int|string $id What the contents in the cache are called 
     358     * @param int|string $key What the contents in the cache are called 
    359359     * @param string $group Where the cache contents are grouped 
    360360     * @param bool $force Optional. Whether to force the unsetting of the cache 
     
    362362     * @return bool False if the contents weren't deleted and true on success 
    363363     */ 
    364     function delete($id, $group = 'default', $force = false) { 
     364    function delete($key, $group = 'default', $force = false) { 
    365365        if (empty ($group)) 
    366366            $group = 'default'; 
    367367 
    368         if (!$force && false === $this->get($id, $group)) 
     368        if (!$force && false === $this->get($key, $group)) 
    369369            return false; 
    370370 
    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; 
    373373        return true; 
    374374    } 
     
    402402     * @since 2.0.0 
    403403     * 
    404      * @param int|string $id What the contents in the cache are called 
     404     * @param int|string $key What the contents in the cache are called 
    405405     * @param string $group Where the cache contents are grouped 
    406406     * @return bool|mixed False on failure to retrieve contents or the cache 
    407407     *      contents on success 
    408408     */ 
    409     function get($id, $group = 'default') { 
     409    function get($key, $group = 'default') { 
    410410        if ( empty ($group) ) 
    411411            $group = 'default'; 
    412412 
    413         if ( isset ($this->cache[$group][$id]) ) { 
     413        if ( isset ($this->cache[$group][$key]) ) { 
    414414            $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]; 
    417417            else 
    418                 return $this->cache[$group][$id]; 
     418                return $this->cache[$group][$key]; 
    419419        } 
    420420 
    421         if ( isset ($this->non_existent_objects[$group][$id]) ) 
     421        if ( isset ($this->non_existent_objects[$group][$key]) ) 
    422422            return false; 
    423423 
    424         $this->non_existent_objects[$group][$id] = true; 
     424        $this->non_existent_objects[$group][$key] = true; 
    425425        $this->cache_misses += 1; 
    426426        return false; 
     
    432432     * @since 3.3.0 
    433433     * 
    434      * @param int|string $id The cache ID to increment 
     434     * @param int|string $key The cache ID to increment 
    435435     * @param int $offset The amount by which to increment the item's value.  Default is 1. 
    436      * @param string $flag The group the key is in. 
     436     * @param string $group The group the key is in. 
    437437     * @return false|int False on failure, the item's new value on success. 
    438438     */ 
    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 ] ) ) 
    441441            return false; 
    442442 
    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; 
    445445 
    446446        $offset = (int) $offset; 
    447447 
    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 ]; 
    454454    } 
    455455 
     
    460460     * @see WP_Object_Cache::set() 
    461461     * 
    462      * @param int|string $id What to call the contents in the cache 
     462     * @param int|string $key What to call the contents in the cache 
    463463     * @param mixed $data The contents to store in the cache 
    464464     * @param string $group Where to group the cache contents 
     
    466466     * @return bool False if not exists, true if contents were replaced 
    467467     */ 
    468     function replace($id, $data, $group = 'default', $expire = '') { 
     468    function replace($key, $data, $group = 'default', $expire = '') { 
    469469        if (empty ($group)) 
    470470            $group = 'default'; 
    471471 
    472         if ( false === $this->get($id, $group) ) 
     472        if ( false === $this->get($key, $group) ) 
    473473            return false; 
    474474 
    475         return $this->set($id, $data, $group, $expire); 
     475        return $this->set($key, $data, $group, $expire); 
    476476    } 
    477477 
     
    493493     * 
    494494     * The cache contents is grouped by the $group parameter followed by the 
    495      * $id. This allows for duplicate ids in unique groups. Therefore, naming of 
     495     * $key. This allows for duplicate ids in unique groups. Therefore, naming of 
    496496     * the group should be used with care and should follow normal function 
    497497     * naming guidelines outside of core WordPress usage. 
     
    503503     * @since 2.0.0 
    504504     * 
    505      * @param int|string $id What to call the contents in the cache 
     505     * @param int|string $key What to call the contents in the cache 
    506506     * @param mixed $data The contents to store in the cache 
    507507     * @param string $group Where to group the cache contents 
     
    509509     * @return bool Always returns true 
    510510     */ 
    511     function set($id, $data, $group = 'default', $expire = '') { 
     511    function set($key, $data, $group = 'default', $expire = '') { 
    512512        if ( empty ($group) ) 
    513513            $group = 'default'; 
     
    519519            $data = clone $data; 
    520520 
    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]); 
    525525 
    526526        return true; 
Note: See TracChangeset for help on using the changeset viewer.