remote_api = $remote_api; $this->cache = $cache; } /** * Implements caching for the Remote API interface. * * @param array $query The query arguments to send to the remote API. * @param bool $associative Always `false`, just present to make definition compatible * with interface. * @return array|object|WP_Error The response from the remote API, or false if the * response is empty. */ public function get_items( array $query, bool $associative = false ) { $cache_key = 'parsely_api_' . wp_hash( $this->remote_api->get_endpoint() ) . '_' . wp_hash( (string) wp_json_encode( $query ) ); /** * Variable. * * @var array|false */ $items = $this->cache->get( $cache_key, self::CACHE_GROUP ); if ( false === $items ) { $items = $this->remote_api->get_items( $query ); $this->cache->set( $cache_key, $items, self::CACHE_GROUP, self::OBJECT_CACHE_TTL ); } return $items; } /** * Returns whether the endpoint is available for access by the current * user. * * @since 3.7.0 * @since 3.14.0 Renamed from `is_user_allowed_to_make_api_call()`. * @since 3.16.0 Added the `$request` parameter. * * @param WP_REST_Request|null $request The request object. * @return bool */ public function is_available_to_current_user( $request = null ): bool { return $this->remote_api->is_available_to_current_user( $request ); } }