Configure HERE Data SDK for C++

OCMAM uses the HERE Data SDK for C++ to access the HERE platform.

In this section, learn how to create the following instances:

Create a Network instance

To access data from the HERE platform, create a Network instance.


#include <olp/core/client/OlpClientSettingsFactory.h>
auto network = olp::client::OlpClientSettingsFactory::
    CreateDefaultNetworkRequestHandler( );

Create a TaskScheduler instance

For the SDK to handle requests asynchronously, create a TaskScheduler instance and specify the number of threads that the SDK should use.

Note: If you do not define the TaskScheduler explicitly or set the number of threads to 1, the SDK will handle all requests synchronously.


#include <olp/core/client/OlpClientSettingsFactory.h>
const std::shared_ptr< olp::thread::TaskScheduler > task_scheduler
    = olp::client::OlpClientSettingsFactory::CreateDefaultTaskScheduler( 4u );

In the example above, 4 is the number of threads to be used by the SDK.

Create a CacheSettings instance

To configure the cache, create a CacheSettings instance with the following parameters:

  • disk_path_mutable – the path to the mutable cache. If it is not set, the downloaded data is stored in the memory cache and limited by its size (see max_memory_cache_size).

    For more information on the different storage types, see the related instruction.

  • disk_path_protected – the path to the protected cache. It is the primary place where the SDK looks for information. This cache type can only be used for map regions. To learn more about the protected cache, see Manage data in protected cache.

  • max_memory_cache_size – the upper limit of the memory data cache size (in bytes). If it is set to 0, the memory cache is not used. The default value is 1 MB. If the size of the downloaded data is greater than the memory cache size, the data is not stored in this cache.

  • max_disk_storage – the upper limit (in bytes) of the disk space that can be used by the mutable cache. The default value is 32 MB. To never evict data, set this parameter to -1.

  • eviction_policy – the eviction policy for the mutable cache. Eviction starts when 90% of the specified max_disk_storage value is reached and stops when it decreases to 85%. The default value is EvictionPolicy::kLeastRecentlyUsed. The eviction_policy is not taken into account if any of the following is true:

    • disk_path_mutable is not set.
    • max_disk_storage is set to -1.
    • openOption is set to OpenOptions::ReadOnly.
  • openOption – the mode in which you want to open the disk cache. By default, the disk cache opens in the read-write mode. To open it in the read-only mode, set openOption to OpenOptions::ReadOnly. To verify the checksum of all data that is read, use the OpenOptions::CheckCrc value.

  • compression – the compression policy for the database. By default, compression is applied to the data before storing. If you want to disable compression, set the parameter to kNoCompression. This parameter is dynamic, and you can change it between runs.

#include <olp/core/cache/CacheSettings.h>
olp::cache::CacheSettings cache_settings;
cache_settings.disk_path_mutable = "/tmp/MutableCache";
cache_settings.disk_path_protected = "/tmp/ProtectedCache";
cache_settings.max_memory_cache_size = 1024ull * 1024ull * 10ull;
cache_settings.max_disk_storage = 1024ull * 1024ull * 1024ull * 4ull;
cache_settings.eviction_policy = olp::cache::EvictionPolicy::kLeastRecentlyUsed;
cache_settings.openOption = olp::cache::OpenOptions::CheckCrc;
cache_settings.compression = olp::cache::CompressionType::kNoCompression;

For more information on all available CacheSettings parameters, see the related file in the Data SDK for C++ repo.

Create a RetrySettings instance

To customize how the SDK treats failed requests, create the RetrySettings instance with the following parameters:

  • max_attempts – the maximum number of retry attempts that are performed internally before passing the failure result to the user. The default value is 3 attempts. The retries are performed only if the retry_condition is met.

  • retry_condition – a parameter that checks whether the retry is desirable.

  • backdown_strategy – the delay between retries when a request fails. Based on how you want to compute the wait time for the next retry attempt, use one of the following strategies:

    • ExponentialBackdownStrategy – to compute the wait time based on the exponential backoff with the added jitter. The default value.
    • EqualJitterBackdownStrategy – to compute the wait time based on the number of retries and initial backdown period.
  • timeout – the overall connection timeout limit (in seconds), including all retries. The default value is 60 seconds.

#include <olp/core/cache/RetrySettings.h>
olp::client::RetrySettings retry_settings;
retry_settings.max_attempts = 4;
retry_settings.retry_condition = [](const olp::client::HttpResponse& response) {
  return (response.status >= olp::http::HttpStatusCode::INTERNAL_SERVER_ERROR &&
       response.status <= olp::http::HttpStatusCode::NETWORK_CONNECT_TIMEOUT) ||
      response.status == olp::http::HttpStatusCode::TOO_MANY_REQUESTS;
retry_settings.backdown_strategy = olp::client::EqualJitterBackdownStrategy{};
retry_settings.timeout = 90;

For information on all available RetrySettings, see the related article in the API Reference of Data SDK for C++ .

results matching ""

    No results matching ""