WordPress.org

Make WordPress Core

Changeset 20089


Ignore:
Timestamp:
03/02/2012 09:10:37 PM (6 years ago)
Author:
ryan
Message:

Fix NULL and FALSE in WP_Object_Cache and make found/not-found unambiguous. Props andy. fixes #20004

File:
1 edited

Legend:

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

    r19712 r20089  
    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
     
    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
     
    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;
     
    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 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     *
Note: See TracChangeset for help on using the changeset viewer.