WordPress.org

Make WordPress Core

Ticket #18607: 18607.diff

File 18607.diff, 12.2 KB (added by ryan, 7 years ago)
  • wp-includes/cache.php

     
    1717 *
    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) {
     24function wp_cache_add($key, $data, $group = '', $expire = 0) {
    2525        global $wp_object_cache;
    2626
    27         return $wp_object_cache->add($key, $data, $flag, $expire);
     27        return $wp_object_cache->add($key, $data, $group, $expire);
    2828}
    2929
    3030/**
     
    5252 *
    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 = '' ) {
     58function wp_cache_decr( $key, $offset = 1, $group = '' ) {
    5959        global $wp_object_cache;
    6060
    61         return $wp_object_cache->decr( $key, $offset, $flag );
     61        return $wp_object_cache->decr( $key, $offset, $group );
    6262}
    6363
    6464/**
     
    6868 * @uses $wp_object_cache Object Cache Class
    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 = '') {
     75function wp_cache_delete($key, $group = '') {
    7676        global $wp_object_cache;
    7777
    78         return $wp_object_cache->delete($id, $flag);
     78        return $wp_object_cache->delete($key, $group);
    7979}
    8080
    8181/**
     
    100100 * @uses $wp_object_cache Object Cache Class
    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 = '') {
     108function wp_cache_get($key, $group = '') {
    109109        global $wp_object_cache;
    110110
    111         return $wp_object_cache->get($id, $flag);
     111        return $wp_object_cache->get($key, $group);
    112112}
    113113
    114114/**
     
    120120 *
    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 = '' ) {
     126function wp_cache_incr( $key, $offset = 1, $group = '' ) {
    127127        global $wp_object_cache;
    128128
    129         return $wp_object_cache->incr( $key, $offset, $flag );
     129        return $wp_object_cache->incr( $key, $offset, $group );
    130130}
    131131
    132132/**
     
    148148 *
    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) {
     155function wp_cache_replace($key, $data, $group = '', $expire = 0) {
    156156        global $wp_object_cache;
    157157
    158         return $wp_object_cache->replace($key, $data, $flag, $expire);
     158        return $wp_object_cache->replace($key, $data, $group, $expire);
    159159}
    160160
    161161/**
     
    167167 *
    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) {
     174function wp_cache_set($key, $data, $group = '', $expire = 0) {
    175175        global $wp_object_cache;
    176176
    177         return $wp_object_cache->set($key, $data, $flag, $expire);
     177        return $wp_object_cache->set($key, $data, $group, $expire);
    178178}
    179179
    180180/**
     
    286286         *
    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
    292292         * @param int $expire When to expire 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
    305305        /**
     
    321321         *
    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;
     338                $this->cache[ $group ][ $key ] -= $offset;
    339339
    340                 if ( $this->cache[ $group ][ $id ] < 0 )
    341                         $this->cache[ $group ][ $id ] = 0;
     340                if ( $this->cache[ $group ][ $key ] < 0 )
     341                        $this->cache[ $group ][ $key ] = 0;
    342342
    343                 return $this->cache[ $group ][ $id ];
     343                return $this->cache[ $group ][ $key ];
    344344        }
    345345
    346346        /**
     
    355355         *
    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
    361361         *              ID in the group
    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        }
    375375
     
    401401         *
    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;
    427427        }
     
    431431         *
    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;
     448                $this->cache[ $group ][ $key ] += $offset;
    449449
    450                 if ( $this->cache[ $group ][ $id ] < 0 )
    451                         $this->cache[ $group ][ $id ] = 0;
     450                if ( $this->cache[ $group ][ $key ] < 0 )
     451                        $this->cache[ $group ][ $key ] = 0;
    452452
    453                 return $this->cache[ $group ][ $id ];
     453                return $this->cache[ $group ][ $key ];
    454454        }
    455455
    456456        /**
     
    459459         * @since 2.0.0
    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
    465465         * @param int $expire When to expire 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
    478478        /**
     
    492492         * Sets the data contents into the cache
    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.
    498498         *
     
    502502         *
    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
    508508         * @param int $expire Not Used
    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';
    514514
     
    518518                if ( is_object($data) )
    519519                        $data = clone $data;
    520520
    521                 $this->cache[$group][$id] = $data;
     521                $this->cache[$group][$key] = $data;
    522522
    523                 if ( isset($this->non_existent_objects[$group][$id]) )
    524                         unset ($this->non_existent_objects[$group][$id]);
     523                if ( isset($this->non_existent_objects[$group][$key]) )
     524                        unset ($this->non_existent_objects[$group][$key]);
    525525
    526526                return true;
    527527        }