Automattic\WooCommerce\Internal\Api

QueryCache::read_from_opcacheprivateWC 1.0

Read a cached DocumentNode from the OPcache file backend.

Method of the class: QueryCache{}

No Hooks.

Returns

DocumentNode|false.

Usage

// private - for code of main (parent) class only
$result = $this->read_from_opcache( $hash );
$hash(string) (required)
The SHA-256 hash.

QueryCache::read_from_opcache() code WC 10.9.1

private function read_from_opcache( string $hash ) {
	$path = self::get_opcache_cache_dir() . '/' . $hash . '.php';

	if ( ! is_file( $path ) ) {
		return false;
	}

	// File contents are produced by self::write_to_opcache() and only
	// ever return a primitive array. The caller falls back to parsing
	// when the include returns a non-array.
	$data = include $path;

	if ( ! is_array( $data ) ) {
		return false;
	}

	try {
		return AST::fromArray( $data );
	} catch ( \Throwable $e ) {
		return false;
	} finally {
		OpcacheFileExpiry::ensure_scheduled();
	}
}