WP_AI_Client_Cache::getMultiple( iterable $keys, mixed $default_value = null ): array<string,

In this article

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

Return

array<string, mixed> A list of key => value pairs.

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

VersionDescription
7.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.