Make WordPress Core

Ticket #20875: 20875.8.diff

File 20875.8.diff, 3.3 KB (added by donmhico, 6 years ago)
  • src/wp-includes/cache.php

    diff --git src/wp-includes/cache.php src/wp-includes/cache.php
    index ea14e78b4d..6c44c4ac32 100644
    function wp_cache_get( $key, $group = '', $force = false, &$found = null ) { 
    123123        return $wp_object_cache->get( $key, $group, $force, $found );
    124124}
    125125
     126/**
     127 * Gets multiple values from cache in one call.
     128 *
     129 * @since 5.4.0
     130 * @uses $wp_object_cache Object Cache Class
     131 *
     132 * @param array       $keys   Array of keys to get from group.
     133 * @param string      $group  Optional. Where the cache contents are grouped. Default empty.
     134 * @param bool        $force  Optional. Whether to force an update of the local cache from the persistent
     135 *                            cache. Default false.
     136 * @return array|bool Array of values.
     137 */
     138function wp_cache_multiple_get( $keys, $group = '', $force = false ) {
     139        global $wp_object_cache;
     140
     141        return $wp_object_cache->get_multiple( $keys, $group, $force );
     142}
     143
    126144/**
    127145 * Increment numeric cache item's value
    128146 *
    class WP_Object_Cache { 
    566584                return false;
    567585        }
    568586
     587        /**
     588         * Retrieves multiple values from the cache.
     589         *
     590         * @since  5.4.0
     591         *
     592         * @param array $keys        Array of keys to fetch.
     593         * @param bool  $force       Optional. Unused. Whether to force a refetch rather than relying on the local
     594         *                           cache. Default false.
     595         *
     596         * @return array Array of values organized into groups.
     597         */
     598        public function get_multiple( $keys, $group = 'default', $force = false ) {
     599                $values = array();
     600
     601                foreach ( $keys as $key ) {
     602                        $values[ $key ] = $this->get( $key, $group, $force );
     603                }
     604
     605                return $values;
     606        }
     607
    569608        /**
    570609         * Increments numeric cache item's value.
    571610         *
  • src/wp-includes/load.php

    diff --git src/wp-includes/load.php src/wp-includes/load.php
    index 9a24cfad4b..d8873dcba0 100644
    function wp_not_installed() { 
    614614                wp_redirect( $link );
    615615                die();
    616616        }
     617
     618        if ( ! function_exists( 'wp_cache_multiple_get' ) ) {
     619                require_once( ABSPATH . WPINC . '/cache-compat.php' );
     620        }
    617621}
    618622
    619623/**
  • tests/phpunit/tests/cache.php

    diff --git tests/phpunit/tests/cache.php tests/phpunit/tests/cache.php
    index a9534f875c..ac910fe0cb 100644
    class Tests_Cache extends WP_UnitTestCase { 
    315315                // Make sure $fake_key is not stored.
    316316                $this->assertFalse( wp_cache_get( $fake_key ) );
    317317        }
     318
     319        /**
     320         * @ticket 20875
     321         */
     322        public function test_get_multiple() {
     323                wp_cache_set( 'foo1', 'bar', 'group1' );
     324                wp_cache_set( 'foo2', 'bar', 'group1' );
     325                wp_cache_set( 'foo1', 'bar', 'group2' );
     326
     327                $found = wp_cache_multiple_get( array( 'foo1', 'foo2', 'foo3', ), 'group1' );
     328
     329                $expected = array(
     330                        'foo1' => 'bar',
     331                        'foo2' => 'bar',
     332                        'foo3' => false,
     333                );
     334
     335                $this->assertSame( $expected, $found );
     336        }
    318337}
  • tests/phpunit/tests/pluggable.php

    diff --git tests/phpunit/tests/pluggable.php tests/phpunit/tests/pluggable.php
    index 73ca7de806..48a7d3ac00 100644
    class Tests_Pluggable extends WP_UnitTestCase { 
    290290                                                'force' => false,
    291291                                                'found' => null,
    292292                                        ),
     293                                        'wp_cache_multiple_get'              => array(
     294                                                'keys',
     295                                                'group' => '',
     296                                                'force' => false,
     297                                        ),
    293298                                        'wp_cache_incr'                      => array(
    294299                                                'key',
    295300                                                'offset' => 1,