Make WordPress Core

Ticket #20875: 20875.diff

File 20875.diff, 3.3 KB (added by tollmanz, 13 years ago)
  • wp-includes/cache.php

     
    114114}
    115115
    116116/**
     117 * Gets multiple values from cache in one call.
     118 *
     119 * Key/group association is handled by assuming all keys have the same group
     120 * if string or single value array is passed as the 'groups' value. If 'groups'
     121 * is an array with more than 1 value, then groups[n] corresponds with keys[n].
     122 * If there are more 'keys' values then 'groups' values, remaining keys will be
     123 * pulled from the 'default' group.
     124 *
     125 * @since   3.?
     126 * @uses    $wp_object_cache Object Cache Class
     127 * @see     WP_Object_Cache::get_multi()
     128 *
     129 * @param   mixed       $keys       Array of keys associated with values.
     130 * @param   mixed       $groups     Array of groups associated with keys.
     131 * @return  array|bool              Array of values organized into groups.
     132 */
     133function wp_cache_get_multi( $keys, $groups = '' ) {
     134        global $wp_object_cache;
     135
     136        return $wp_object_cache->get_multi( $keys, $groups );
     137}
     138
     139/**
    117140 * Increment numeric cache item's value
    118141 *
    119142 * @since 3.3.0
     
    417440        }
    418441
    419442        /**
     443         * Gets multiple values from cache in one call.
     444         *
     445         * Key/group association is handled by assuming all keys have the same group
     446         * if string or single value array is passed as the 'groups' value. If 'groups'
     447         * is an array with more than 1 value, then groups[n] corresponds with keys[n].
     448         * If there are more 'keys' values then 'groups' values, remaining keys will be
     449         * pulled from the 'default' group.
     450         *
     451         * @since   3.?
     452         *
     453         * @param   mixed       $keys       Array of keys associated with values.
     454         * @param   mixed       $groups     Array of groups associated with keys.
     455         * @return  array|bool              Array of values organized into groups.
     456         */
     457        function get_multi( $keys, $groups = 'default' ) {
     458                $values = array();
     459
     460                // If two strings are sent, do a normal get
     461                if ( is_string( $keys ) && is_string( $groups ) ) {
     462                        $value = $this->get( $keys, $groups );
     463
     464                        if ( false === $value )
     465                                return false;
     466
     467                        $values[ $groups ][ $keys ] = $this->get( $keys, $groups );
     468                        return $values;
     469                }
     470
     471                // Ensure arrays
     472                if ( ! is_array( $keys ) )
     473                        $keys = (array) $keys;
     474
     475                if ( ! is_array( $groups ) )
     476                        $groups = (array) $groups;
     477
     478                // Ensure numerical keying of arrays
     479                $keys = array_values( $keys );
     480                $groups = array_values( $groups );
     481
     482                /**
     483                 * Loop through keys to get values. If $groups[ $i ] exists, assume
     484                 * it belongs with $keys[ $i ]. If there is only one value in $groups,
     485                 * assume that group corresponds to all $keys. Default is to make the
     486                 * group 'default'.
     487                 */
     488                for ( $i = 0; $i < count( $keys ); $i++ ) {
     489                        if ( isset( $groups[ $i ] ) && ! empty( $groups[ $i ] ) )
     490                                $values[ $groups[ $i ] ][ $keys[ $i ] ] = $this->get( $keys[ $i ], $groups[ $i ] );
     491                        elseif ( count( $groups ) == 1 && isset( $groups[0] ) && ! empty( $groups[ 0 ] ) )
     492                                $values[ $groups[ $i ] ][ $keys[ $i ] ] = $this->get( $keys[ $i ], $groups[0] );
     493                        else
     494                                $values[ $groups[ $i ] ][ $keys[ $i ] ] = $this->get( $keys[ $i ], 'default' );
     495                }
     496
     497                return $values;
     498        }
     499
     500        /**
    420501         * Increment numeric cache item's value
    421502         *
    422503         * @since 3.3.0