Obtains multiple cache items by their unique keys.
Parameters
$keys<span class="iterable”>iterablerequired- A list of keys that can be obtained in a single operation.
$default_valuemixedoptional- Default value to return for keys that do not exist.
Default:
null
Source
public function getMultiple( $keys, $default_value = null ): array {
/**
* Keys array.
*
* @var array<string> $keys_array
*/
$keys_array = $this->iterable_to_array( $keys );
$values = wp_cache_get_multiple( $keys_array, self::CACHE_GROUP );
$result = array();
foreach ( $keys_array as $key ) {
if ( false === $values[ $key ] ) {
// Could be a stored false or a cache miss — disambiguate via get().
$result[ $key ] = $this->get( $key, $default_value );
} else {
$result[ $key ] = $values[ $key ];
}
}
return $result;
}
Changelog
| Version | Description |
|---|---|
| 7.0.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.