Automattic\WooCommerce\Internal\Api
QueryCache::parse_and_cache
Parse a query, cache the resulting AST, and return the DocumentNode.
Writes to OPcache when enabled and usable. APQ registrations always also write to the object cache so hash-only lookups still resolve if OPcache later becomes unavailable (toggle off, dir unwritable, files cleaned up, or a silent write_to_opcache failure).
Returns an error array if the query has a syntax error.
Метод класса: QueryCache{}
Хуков нет.
Возвращает
DocumentNode|Массив.
Использование
// private - только в коде основоного (родительского) класса $result = $this->parse_and_cache( $query, $hash, $for_apq );
- $query(строка) (обязательный)
- The GraphQL query string.
- $hash(строка) (обязательный)
- The SHA-256 hash to cache under.
- $for_apq(true|false)
- Whether the request is an APQ registration.
По умолчанию:false
Код QueryCache::parse_and_cache() QueryCache::parse and cache WC 11.0.1
private function parse_and_cache( string $query, string $hash, bool $for_apq = false ) {
$document = $this->parse( $query );
if ( ! $document instanceof DocumentNode ) {
return $document;
}
$used_opcache = Main::is_opcache_enabled() && $this->is_opcache_usable();
if ( $used_opcache ) {
$this->write_to_opcache( $hash, $document );
}
if ( $for_apq || ( Main::is_object_cache_enabled() && ! $used_opcache ) ) {
wp_cache_set( $this->build_cache_key( $hash ), $document->toArray(), self::CACHE_GROUP, self::get_cache_ttl() );
}
return $document;
}