Make WordPress Core

Ticket #20875: 20875.7.diff

File 20875.7.diff, 3.0 KB (added by spacedmonkey, 6 years ago)
  • src/wp-includes/cache.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    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 *
     
    556574                return false;
    557575        }
    558576
     577        /**
     578         * Retrieves multiple values from the cache.
     579         *
     580         * @since  5.4.0
     581         *
     582         * @param array $keys        Array of keys to fetch.
     583         * @param bool  $force       Optional. Unused. Whether to force a refetch rather than relying on the local
     584         *                           cache. Default false.
     585         *
     586         * @return array Array of values organized into groups.
     587         */
     588        public function get_multiple( $keys, $group = 'default', $force = false ) {
     589                $values = array();
     590
     591                foreach ( $keys as $key ) {
     592                        $values[ $key ] = $this->get( $key, $group, $force );
     593                }
     594
     595                return $values;
     596        }
     597
    559598        /**
    560599         * Increments numeric cache item's value.
    561600         *
  • src/wp-includes/load.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    613613                wp_redirect( $link );
    614614                die();
    615615        }
     616
     617        if ( ! function_exists( 'wp_cache_multiple_get' ) ) {
     618                require_once( ABSPATH . WPINC . '/cache-compat.php' );
     619        }
    616620}
    617621
    618622/**
  • tests/phpunit/tests/cache.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    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}