diff --git src/wp-includes/cache.php src/wp-includes/cache.php
index 9da8d02..f54f6da 100644
|
|
|
function wp_cache_get( $key, $group = '', $force = false, &$found = null ) { |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
| | 127 | * Gets multiple values from cache in one call. |
| | 128 | * |
| | 129 | * @since 4.6.0 |
| | 130 | * @uses $wp_object_cache Object Cache Class |
| | 131 | * @see WP_Object_Cache::get_multi() |
| | 132 | * |
| | 133 | * @param array $keys Multidimensional array, where the array keys are cache group names, |
| | 134 | * and the values are arrays of keys to be fetched from that group. |
| | 135 | * @return array|bool Array of values organized into groups. |
| | 136 | */ |
| | 137 | function wp_cache_get_multi( $keys ) { |
| | 138 | global $wp_object_cache; |
| | 139 | |
| | 140 | return $wp_object_cache->get_multi( $keys ); |
| | 141 | } |
| | 142 | |
| | 143 | /** |
| 127 | 144 | * Increment numeric cache item's value |
| 128 | 145 | * |
| 129 | 146 | * @since 3.3.0 |
| … |
… |
class WP_Object_Cache { |
| 560 | 577 | } |
| 561 | 578 | |
| 562 | 579 | /** |
| | 580 | * Retrieves multiple values from the cache. |
| | 581 | * |
| | 582 | * @since 4.6.0 |
| | 583 | * @access public |
| | 584 | * |
| | 585 | * @param array $keys Multidimensional array, where the array keys are cache group names, |
| | 586 | * and the values are arrays of keys to be fetched from that group. |
| | 587 | * @return array Array of values organized into groups. |
| | 588 | */ |
| | 589 | public function get_multi( $keys ) { |
| | 590 | $values = array(); |
| | 591 | |
| | 592 | foreach ( $keys as $group => $group_keys ) { |
| | 593 | foreach ( $group_keys as $group_key ) { |
| | 594 | $values[ $group ][ $group_key ] = $this->get( $group_key, $group ); |
| | 595 | } |
| | 596 | } |
| | 597 | |
| | 598 | return $values; |
| | 599 | } |
| | 600 | |
| | 601 | /** |
| 563 | 602 | * Increments numeric cache item's value. |
| 564 | 603 | * |
| 565 | 604 | * @since 3.3.0 |
diff --git tests/phpunit/tests/cache.php tests/phpunit/tests/cache.php
index 87028c5..1af1a5d 100644
|
|
|
class Tests_Cache extends WP_UnitTestCase { |
| 313 | 313 | // Make sure $fake_key is not stored |
| 314 | 314 | $this->assertFalse( wp_cache_get( $fake_key ) ); |
| 315 | 315 | } |
| | 316 | |
| | 317 | /** |
| | 318 | * @group 20875 |
| | 319 | */ |
| | 320 | public function test_get_multi() { |
| | 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_multi( 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 | } |
| 316 | 349 | } |