Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableDataStoreMeta::get_meta_data_for_object_ids_from_cacheprivateWC 1.0

Retrieve raw object meta from cache for the given a set of IDs.

Method of the class: OrdersTableDataStoreMeta{}

No Hooks.

Returns

\stdClass[][]. An array, keyed by the object IDs, containing arrays of raw meta data for each object.

Usage

// private - for code of main (parent) class only
$result = $this->get_meta_data_for_object_ids_from_cache( $object_ids ): array;
$object_ids(int[]) (required)
List of object IDs.

OrdersTableDataStoreMeta::get_meta_data_for_object_ids_from_cache() code WC 11.0.1

private function get_meta_data_for_object_ids_from_cache( array $object_ids ): array {
	$cache_engine = wc_get_container()->get( WPCacheEngine::class );
	$meta_data    = $cache_engine->get_cached_objects( $object_ids, $this->get_cache_group() );

	foreach ( $meta_data as $object_id => $object_meta ) {
		if ( null === $object_meta ) {
			unset( $meta_data[ $object_id ] );
			continue;
		}

		if ( $this->is_valid_cached_meta( $object_meta ) ) {
			continue;
		}

		/*
		 * A malformed cache entry - not an array, or an array whose elements are not complete
		 * meta rows - would fatal or silently load wrong values downstream
		 * (WC_Data_Store_WP::filter_raw_meta_data() reads $meta->meta_key; WC_Data::init_meta_data()
		 * reads meta_id/meta_key/meta_value). This can happen when a third-party persistent
		 * object cache returns a corrupt or cross-contaminated value. Invalidate the entry and
		 * exclude it from the cache hits so it is re-read from the database in this same
		 * request, and surface it for diagnosis.
		 */
		$cache_engine->delete_cached_object( $object_id, $this->get_cache_group() );
		wc_get_logger()->warning(
			sprintf(
				'Discarded a corrupt HPOS meta cache entry for order %1$d; it will be re-read from the database.',
				(int) $object_id
			),
			array( 'source' => 'hpos-data-cache' )
		);
		unset( $meta_data[ $object_id ] );
	}

	return $meta_data;
}