Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r18995 r20091  
    5252 *
    5353 * @param int|string $key The cache key to increment
    54  * @param int $offset The amount by which to decrement the item's value.  Default is 1.
     54 * @param int $offset The amount by which to decrement the item's value. Default is 1.
    5555 * @param string $group The group the key is in.
    5656 * @return false|int False on failure, the item's new value on success.
    … …  
    104104 * @param string $group Where the cache contents are grouped
    105105 * @param bool $force Whether to force an update of the local cache from the persistent cache (default is false)
     106 * @param &bool $found Whether key was found in the cache. Disambiguates a return of false, a storable value.
    106107 * @return bool|mixed False on failure to retrieve contents or the cache
    107108 *              contents on success
    108109 */
    109 function wp_cache_get( $key, $group = '', $force = false ) {
    110         global $wp_object_cache;
    111 
    112         return $wp_object_cache->get( $key, $group, $force );
     110function wp_cache_get( $key, $group = '', $force = false, &$found = null ) {
     111        global $wp_object_cache;
     112
     113        return $wp_object_cache->get( $key, $group, $force, $found );
    113114}
    114115
    … …  
    121122 *
    122123 * @param int|string $key The cache key to increment
    123  * @param int $offset The amount by which to increment the item's value.  Default is 1.
     124 * @param int $offset The amount by which to increment the item's value. Default is 1.
    124125 * @param string $group The group the key is in.
    125126 * @return false|int False on failure, the item's new value on success.
    … …  
    205206
    206207/**
    207  * Reset internal cache keys and structures.  If the cache backend uses global blog or site IDs as part of its cache keys,
     208 * Reset internal cache keys and structures. If the cache backend uses global blog or site IDs as part of its cache keys,
    208209 * this function instructs the backend to reset those keys and perform any cleanup since blog or site IDs have changed since cache init.
    209210 *
    … …  
    273274         * Adds data to the cache if it doesn't already exist.
    274275         *
    275          * @uses WP_Object_Cache::get Checks to see if the cache already has data.
     276         * @uses WP_Object_Cache::_exists Checks to see if the cache already has data.
    276277         * @uses WP_Object_Cache::set Sets the data after the checking the cache
    277278         *              contents existence.
    … …  
    289290                        return false;
    290291
    291                 if ( empty ($group) )
     292                if ( empty( $group ) )
    292293                        $group = 'default';
    293294
    294                 if (false !== $this->get($key, $group))
     295                if ( $this->_exists($key, $group) )
    295296                        return false;
    296297
    … …  
    318319         *
    319320         * @param int|string $key The cache key to increment
    320          * @param int $offset The amount by which to decrement the item's value.  Default is 1.
     321         * @param int $offset The amount by which to decrement the item's value. Default is 1.
    321322         * @param string $group The group the key is in.
    322323         * @return false|int False on failure, the item's new value on success.
    323324         */
    324325        function decr( $key, $offset = 1, $group = 'default' ) {
    325                 if ( ! isset( $this->cache[ $group ][ $key ] ) )
     326                if ( ! $this->_exists( $key, $group ) )
    326327                        return false;
    327328
    … …  
    355356         */
    356357        function delete($key, $group = 'default', $force = false) {
    357                 if (empty ($group))
     358                if ( empty( $group ) )
    358359                        $group = 'default';
    359360
    360                 if (!$force && false === $this->get($key, $group))
     361                if ( ! $force && ! $this->_exists( $key, $group ) )
    361362                        return false;
    362363
    363                 unset ($this->cache[$group][$key]);
     364                unset( $this->cache[$group][$key] );
    364365                return true;
    365366        }
    … …  
    395396         *              contents on success
    396397         */
    397         function get( $key, $group = 'default', $force = false) {
    398                 if ( empty ($group) )
     398        function get( $key, $group = 'default', $force = false, &$found = null ) {
     399                if ( empty( $group ) )
    399400                        $group = 'default';
    400401
    401                 if ( isset ($this->cache[$group][$key]) ) {
     402                if ( $this->_exists( $key, $group ) ) {
     403                        $found = true;
    402404                        $this->cache_hits += 1;
    403405                        if ( is_object($this->cache[$group][$key]) )
    … …  
    407409                }
    408410
     411                $found = false;
    409412                $this->cache_misses += 1;
    410413                return false;
    … …  
    417420         *
    418421         * @param int|string $key The cache key to increment
    419          * @param int $offset The amount by which to increment the item's value.  Default is 1.
     422         * @param int $offset The amount by which to increment the item's value. Default is 1.
    420423         * @param string $group The group the key is in.
    421424         * @return false|int False on failure, the item's new value on success.
    422425         */
    423426        function incr( $key, $offset = 1, $group = 'default' ) {
    424                 if ( ! isset( $this->cache[ $group ][ $key ] ) )
     427                if ( empty( $group ) )
     428                        $group = 'default';
     429
     430                if ( ! $this->_exists( $key, $group ) )
    425431                        return false;
    426432
    … …  
    451457         */
    452458        function replace($key, $data, $group = 'default', $expire = '') {
    453                 if (empty ($group))
     459                if ( empty( $group ) )
    454460                        $group = 'default';
    455461
    456                 if ( false === $this->get($key, $group) )
     462                if ( ! $this->_exists( $key, $group ) )
    457463                        return false;
    458464
    … …  
    494500         */
    495501        function set($key, $data, $group = 'default', $expire = '') {
    496                 if ( empty ($group) )
     502                if ( empty( $group ) )
    497503                        $group = 'default';
    498 
    499                 if ( NULL === $data )
    500                         $data = '';
    501504
    502505                if ( is_object($data) )
    … …  
    528531
    529532        /**
     533         * Utility function to determine whether a key exists in the cache.
     534         * @access private
     535         */
     536        protected function _exists($key, $group) {
     537                return isset( $this->cache[$group] ) && is_array( $this->cache[$group] ) && array_key_exists( $key, $this->cache[$group] );
     538        }
     539
     540        /**
    530541         * Sets up object properties; PHP 5 style constructor
    531542         *
    … …  
    554565        }
    555566}
    556 ?>
Note: See TracChangeset for help on using the changeset viewer.