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. Built from https://develop.svn.wordpress.org/trunk@47938 git-svn-id: http://core.svn.wordpress.org/trunk@47711 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -302,6 +302,27 @@ class WP_Object_Cache {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves multiple values from the cache.
|
||||
*
|
||||
* @since 5.5.0
|
||||
*
|
||||
* @param array $keys Array of keys to fetch.
|
||||
* @param bool $force Optional. Unused. Whether to force a refetch rather than relying on the local
|
||||
* cache. Default false.
|
||||
*
|
||||
* @return array Array of values organized into groups.
|
||||
*/
|
||||
public function get_multiple( $keys, $group = 'default', $force = false ) {
|
||||
$values = array();
|
||||
|
||||
foreach ( $keys as $key ) {
|
||||
$values[ $key ] = $this->get( $key, $group, $force );
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments numeric cache item's value.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user