Make WordPress Core

Ticket #20875: 20875.5.diff

File 20875.5.diff, 3.8 KB (added by spacedmonkey, 8 years ago)
  • src/wp-includes/cache-compat.php

     
     1<?php
     2
     3/**
     4 *  Compatibility for cache drop-ins.
     5 *
     6 * @param $groups
     7 * @since 5.0.0
     8 * @return array
     9 */
     10function wp_cache_get_multiple( $groups ) {
     11        $values = array();
     12
     13        foreach ( $groups as $group => $keys ) {
     14                foreach ( $keys as $key ) {
     15                        $values[ $group ][ $key ] = wp_cache_get( $key, $group );
     16                }
     17        }
     18
     19        return $values;
     20}
     21
     22
     23
  • src/wp-includes/cache.php

    Property changes on: src/wp-includes/cache-compat.php
    ___________________________________________________________________
    Added: svn:executable
    ## -0,0 +1 ##
    +*
    \ No newline at end of property
     
    124124}
    125125
    126126/**
     127 * Gets multiple values from cache in one call.
     128 *
     129 * @since 5.0.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
     
    557573        }
    558574
    559575        /**
     576         * Retrieves multiple values from the cache.
     577         *
     578         * @since 5.0.0
     579         * @access public
     580         *
     581         * @param array $groups Multidimensional array, where the array keys are cache group names,
     582         *                      and the values are arrays of keys to be fetched from that group.
     583         * @return array Array of values organized into groups.
     584         */
     585        public function get_multiple( $groups ) {
     586                $values = array();
     587
     588                foreach ( $groups as $group => $keys ) {
     589                        foreach ( $keys as $key ) {
     590                                $values[ $group ][ $key ] = $this->get( $key, $group );
     591                        }
     592                }
     593
     594                return $values;
     595        }
     596
     597        /**
    560598         * Increments numeric cache item's value.
    561599         *
    562600         * @since 3.3.0
  • src/wp-includes/load.php

     
    570570                wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );
    571571                wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
    572572        }
     573
     574        if ( ! function_exists( 'wp_cache_get_multiple' ) ) {
     575                require_once( ABSPATH . WPINC . '/cache-compat.php' );
     576        }
    573577}
    574578
    575579/**
  • tests/phpunit/tests/cache.php

     
    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_get_multiple( array(
     328                        'group1' => array(
     329                                'foo1',
     330                                'foo2',
     331                                'foo3',
     332                        ),
     333                        'group2' => array(
     334                                'foo1',
     335                        ),
     336                ) );
     337
     338                $expected = array(
     339                        'group1' => array(
     340                                'foo1' => 'bar',
     341                                'foo2' => 'bar',
     342                                'foo3' => false,
     343                        ),
     344                        'group2' => array(
     345                                'foo1' => 'bar',
     346                        ),
     347                );
     348
     349                $this->assertSame( $expected, $found );
     350        }
    318351}