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.
Method of the class: QueryCache{}
No Hooks.
Returns
DocumentNode|Array.
Usage
// private - for code of main (parent) class only $result = $this->parse_and_cache( $query, $hash, $for_apq );
- $query(string) (required)
- The GraphQL query string.
- $hash(string) (required)
- The SHA-256 hash to cache under.
- $for_apq(true|false)
- Whether the request is an APQ registration.
Default:false
QueryCache::parse_and_cache() QueryCache::parse and cache code WC 10.9.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;
}