Make WordPress Core

Ticket #20875: 20875.4.diff

File 20875.4.diff, 3.5 KB (added by boonebgorges, 10 years ago)
  • new file src/wp-includes/cache-compat.php

    diff --git src/wp-includes/cache-compat.php src/wp-includes/cache-compat.php
    new file mode 100644
    index 0000000..ca101a0
    - +  
     1<?php
     2
     3/**
     4 * Compatibility for cache drop-ins.
     5 *
     6 * @since 4.6.0
     7 */
     8
     9if ( ! function_exists( 'wp_cache_get_multiple' ) ) :
     10        function wp_cache_get_multiple( $groups ) {
     11                $values = array();
     12
     13                foreach ( $groups as $group => $keys ) {
     14                        foreach ( $keys as $keys ) {
     15                                $values[ $group ][ $key ] = $this->get( $key, $group );
     16                        }
     17                }
     18
     19                return $values;
     20        }
     21endif;
  • src/wp-includes/cache.php

    diff --git src/wp-includes/cache.php src/wp-includes/cache.php
    index 9da8d02..204b3a6 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 *
     132 * @param array $groups Multidimensional array, where the array keys are cache group names,
     133 *                      and the values are arrays of keys to be fetched from that group.
     134 * @return array|bool Array of values organized into groups.
     135 */
     136function wp_cache_get_multiple( $groups ) {
     137        global $wp_object_cache;
     138
     139        return $wp_object_cache->get_multiple( $groups );
     140}
     141
     142/**
    127143 * Increment numeric cache item's value
    128144 *
    129145 * @since 3.3.0
    class WP_Object_Cache { 
    560576        }
    561577
    562578        /**
     579         * Retrieves multiple values from the cache.
     580         *
     581         * @since 4.6.0
     582         * @access public
     583         *
     584         * @param array $groups Multidimensional array, where the array keys are cache group names,
     585         *                      and the values are arrays of keys to be fetched from that group.
     586         * @return array Array of values organized into groups.
     587         */
     588        public function get_multiple( $groups ) {
     589                $values = array();
     590
     591                foreach ( $groups as $group => $keys ) {
     592                        foreach ( $keys as $key ) {
     593                                $values[ $group ][ $key ] = $this->get( $key, $group );
     594                        }
     595                }
     596
     597                return $values;
     598        }
     599
     600        /**
    563601         * Increments numeric cache item's value.
    564602         *
    565603         * @since 3.3.0
  • src/wp-includes/load.php

    diff --git src/wp-includes/load.php src/wp-includes/load.php
    index b2181c0..c2e8742 100644
    function wp_start_object_cache() { 
    462462                wp_using_ext_object_cache( true );
    463463        }
    464464
    465         if ( ! wp_using_ext_object_cache() )
     465        if ( wp_using_ext_object_cache() ) {
     466                require_once ABSPATH . WPINC . '/cache-compat.php';
     467        } else {
    466468                require_once ( ABSPATH . WPINC . '/cache.php' );
     469        }
    467470
    468471        /*
    469472         * If cache supports reset, reset instead of init if already
  • tests/phpunit/tests/cache.php

    diff --git tests/phpunit/tests/cache.php tests/phpunit/tests/cache.php
    index 87028c5..1a105d0 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         * @ticket 20875
     319         */
     320        public function test_get_multiple() {
     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_multiple( 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}