Automattic\WooCommerce\Internal\Api

QueryCache::get_cached_documentprivateWC 1.0

Retrieve a cached DocumentNode by hash.

Tries OPcache first when enabled and usable, then falls back to the WP object cache. APQ requests pass $for_apq=true so the object cache is consulted regardless of the standard-query toggle, matching the pre-OPcache behaviour where APQ always persisted via the object cache.

Метод класса: QueryCache{}

Хуков нет.

Возвращает

DocumentNode|false.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->get_cached_document( $hash, $for_apq );
$hash(строка) (обязательный)
The SHA-256 hash.
$for_apq(true|false)
Whether the lookup is for an APQ request.
По умолчанию: false

Код QueryCache::get_cached_document() WC 11.0.1

private function get_cached_document( string $hash, bool $for_apq = false ) {
	if ( Main::is_opcache_enabled() && $this->is_opcache_usable() ) {
		$doc = $this->read_from_opcache( $hash );
		if ( false !== $doc ) {
			return $doc;
		}
	}

	if ( $for_apq || Main::is_object_cache_enabled() ) {
		$cached = wp_cache_get( $this->build_cache_key( $hash ), self::CACHE_GROUP );
		if ( is_array( $cached ) ) {
			try {
				return AST::fromArray( $cached );
			} catch ( \Throwable $e ) {
				return false;
			}
		}
	}

	return false;
}