Make WordPress Core


Ignore:
Timestamp:
06/09/2020 07:45:27 PM (4 years ago)
Author:
whyisjake
Message:

Cache API: Introduce wp_cache_get_multi().

Many caching backend have support for multiple gets in a single request. This brings that support to core, with a compatability fallback that will loop over requests if needed.

Fixes: #20875.
Props: nacin, tollmanz, wonderboymusic, ryan, jeremyfelt, spacedmonkey, boonebgorges, dd32, rmccue, ocean90, jipmoors, johnjamesjacoby, tillkruess, donmhico, davidbaumwald, SergeyBiryukov, whyisjake.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/cache.php

    r47122 r47938  
    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( '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}
Note: See TracChangeset for help on using the changeset viewer.