Get data from a versioned layer with a cache

You can get data from a versioned layer with a mutable or protected cache. You can also use the mutable cache to publish data.

To get data from the versioned layer with a cache:

  1. Create the OlpClientSettings object with the path to the needed cache settings properties (disk space, runtime memory limit, maximum file size, in-memory data cache size, options, and paths).

    For instructions, see Create platform client settings.

    Note

    Perform the first call with the valid mutable cache path, and the second call – with the protected cache path.

  2. Create the VersionedLayerClient object with the HERE Resource Name (HRN) of the catalog that contains the layer, the layer ID, catalog version, and the platform client settings from step 1.

    If you do not specify a catalog version, the latest version is used. Depending on the fetch option that you specified in your first API call to the client, the GetLatestVersion method automatically gets the latest version in one of the following ways:

    • For the OnlineIfNotFound fetch option, queries the network, and if an error occurs, checks the cache. If the online version is higher than the cache version, the cache version is updated.
    • For the OnlineOnly fetch option, only queries the network.
    • For the CacheOnly fetch option, only checks the cache.
    olp::dataservice::read::VersionedLayerClient layer_client (
                        client::HRN catalog,
                        std::string layer_id,
                        boost::optional<int64_t> catalog_version,
                        client::OlpClientSettings settings);
    
  3. Create the DataRequest object with the partition ID and one of the following fetch options:

    • (Default) To query network if the requested resource is not found in the cache, use OnlineIfNotFound.
    • To skip cache lookups and query the network right away, use OnlineOnly.
    • To return immediately if a cache lookup fails, use CacheOnly.
    auto request = olp::dataservice::read::DataRequest()
                     .WithPartitionId(first_partition_id)
                     .WithBillingTag(boost::none)
                     .WithFetchOption(FetchOptions::OnlineIfNotFound);
    
  4. Call the GetRequest method with the DataRequest parameter.

    auto future = layer_client.GetData(request);
    
  5. Wait for the DataResponse future.

    olp::dataservice::read::DataResponse data_response =
    future.GetFuture().get();
    

The DataResponse object holds details of the completed operation and is used to determine operation success and access resultant data:

  • IsSuccessful() - if the operation is successful, returns true. Otherwise, returns false.
  • GetResult() - if the operation is successful, returns the following resultant data: olp::dataservice::read::DataResult
  • GetError() - contains error information as a result of an error in the olp::client::ApiError object.
if (data_response.IsSuccessful()) {
    const auto& response_result = data_response.GetResult();
    // Handle success
} else {
    data_response.GetError().GetErrorCode();
    // Handle fail
}

The received data is stored in the cache. You can find the path to the cache in the log message.

results matching ""

    No results matching ""