Make WordPress Core

Ticket #20875: 20875.3.diff

File 20875.3.diff, 2.5 KB (added by boonebgorges, 10 years ago)
  • src/wp-includes/cache.php

    diff --git src/wp-includes/cache.php src/wp-includes/cache.php
    index 9da8d02..f54f6da 100644
    function wp_cache_get( $key, $group = '', $force = false, &$found = null ) { 
    124124}
    125125
    126126/**
     127 * Gets multiple values from cache in one call.
     128 *
     129 * @since 4.6.0
     130 * @uses $wp_object_cache Object Cache Class
     131 * @see WP_Object_Cache::get_multi()
     132 *
     133 * @param array $keys Multidimensional array, where the array keys are cache group names,
     134 *                    and the values are arrays of keys to be fetched from that group.
     135 * @return array|bool Array of values organized into groups.
     136 */
     137function wp_cache_get_multi( $keys ) {
     138        global $wp_object_cache;
     139
     140        return $wp_object_cache->get_multi( $keys );
     141}
     142
     143/**
    127144 * Increment numeric cache item's value
    128145 *
    129146 * @since 3.3.0
    class WP_Object_Cache { 
    560577        }
    561578
    562579        /**
     580         * Retrieves multiple values from the cache.
     581         *
     582         * @since 4.6.0
     583         * @access public
     584         *
     585         * @param array $keys Multidimensional array, where the array keys are cache group names,
     586         *                    and the values are arrays of keys to be fetched from that group.
     587         * @return array Array of values organized into groups.
     588         */
     589        public function get_multi( $keys ) {
     590                $values = array();
     591
     592                foreach ( $keys as $group => $group_keys ) {
     593                        foreach ( $group_keys as $group_key ) {
     594                                $values[ $group ][ $group_key ] = $this->get( $group_key, $group );
     595                        }
     596                }
     597
     598                return $values;
     599        }
     600
     601        /**
    563602         * Increments numeric cache item's value.
    564603         *
    565604         * @since 3.3.0
  • tests/phpunit/tests/cache.php

    diff --git tests/phpunit/tests/cache.php tests/phpunit/tests/cache.php
    index 87028c5..1af1a5d 100644
    class Tests_Cache extends WP_UnitTestCase { 
    313313                // Make sure $fake_key is not stored
    314314                $this->assertFalse( wp_cache_get( $fake_key ) );
    315315        }
     316
     317        /**
     318         * @group 20875
     319         */
     320        public function test_get_multi() {
     321                wp_cache_set( 'foo1', 'bar', 'group1' );
     322                wp_cache_set( 'foo2', 'bar', 'group1' );
     323                wp_cache_set( 'foo1', 'bar', 'group2' );
     324
     325                $found = wp_cache_get_multi( array(
     326                        'group1' => array(
     327                                'foo1',
     328                                'foo2',
     329                                'foo3',
     330                        ),
     331                        'group2' => array(
     332                                'foo1',
     333                        ),
     334                ) );
     335
     336                $expected = array(
     337                        'group1' => array(
     338                                'foo1' => 'bar',
     339                                'foo2' => 'bar',
     340                                'foo3' => false,
     341                        ),
     342                        'group2' => array(
     343                                'foo1' => 'bar',
     344                        ),
     345                );
     346
     347                $this->assertSame( $expected, $found );
     348        }
    316349}