Automattic\WooCommerce\Caching

WPCacheEngine::get_cached_objects()publicWC 1.0

Retrieves a set of objects cached under the given keys.

Method of the class: WPCacheEngine{}

No Hooks.

Return

Array. The cached array of objects keyed by the given keys, values will be null for any non-cached keys.

Usage

$WPCacheEngine = new WPCacheEngine();
$WPCacheEngine->get_cached_objects( $keys, $group );
$keys(string[]) (required)
The keys under which the object to retrieve is cached.
$group(string)
The group under which the object is cached.
Default: ''

WPCacheEngine::get_cached_objects() code WC 9.6.0

public function get_cached_objects( array $keys, string $group = '' ) {
	$prefix  = self::get_cache_prefix( $group );
	$key_map = array_combine(
		$keys,
		array_map(
			function ( $key ) use ( $prefix ) {
				return $prefix . $key;
			},
			$keys
		)
	);

	$cached_values = wp_cache_get_multiple( array_values( $key_map ), $group );
	$return_values = array();
	foreach ( $key_map as $key => $prefixed_key ) {
		if ( isset( $cached_values[ $prefixed_key ] ) && false !== $cached_values[ $prefixed_key ] ) {
			$return_values[ $key ] = $cached_values[ $prefixed_key ];
		} else {
			$return_values[ $key ] = null;
		}
	}

	return $return_values;
}