Manage data in mutable cache

You can update data in the mutable cache or delete a catalog version.

For more information on the mutable cache, see Storage types.

Update data in the mutable cache

Data in the mutable cache is updated incrementally and only per request. When you request to get the latest updates, only the data that has changed is updated, not the entire cache.

The following diagram shows how the incremental update logic works if there is a new catalog version available, and you decided to switch to it and then request a tile.

mutable_cache_update
Figure 1. Incremental update strategy for the mutable cache

Note: When you download data, to omit duplicates and reduce traffic usage, first download regions to the protected cache and then to the mutable cache. Otherwise, downloaded bundles are duplicated in both caches.

To update a catalog to a newer version:

  1. Create a DataStoreServer instance. For more information, see the related instruction.

  2. To check which version is already in the cache, run the GetAvailableVersion method using the catalog HRN and cache type.

    Note: Run this method each time you restart the app to check if catalog data is available offline.

    const auto response = server->GetAvailableVersion( hrn, cache::DefaultCache::CacheType::kMutable );
    
    int64_t available_version = -1;
    if ( !response )
    {
       // There is no stored version in the mutable cache.
    }
    else
    {
        available_version = response.GetResult( );
    }
    
  3. To check if there is a new online catalog version, run the GetLatestVersion method using the catalog handle, and then compare the returned version to the local one.

     std::promise< Response< int64_t > > promise;
     server->GetLatestVersion( catalog_handle,
     [&]( Response< int64_t > response ) { promise.set_value( response ); } );
    
     const auto latest_version = promise.get_future( ).get( );
    

    The GetLatestVersion method first checks which catalog version is available online. In case of failure, the method checks the latest version available in the cache.

  4. Add the catalog with the newer version to the previously created DataStoreServer instance.

    For more information, see the related instruction. Use the new catalog handle in future operations with this catalog version.

You can also set the version to which you want to update the catalog or leave it empty to use the latest available catalog version. For instructions, see "Set a catalog version" in Add catalog to DataStoreServer and DataStoreClient instances.

Now, you can create DataStoreClient instances and add the catalog with the newer version to them.

Evict data from the mutable cache

To enable data eviction from the mutable cache:

  1. Set olp::cache::CacheSettings::max_disk_storage to a specific value. The value should be set in bytes.

    Note: Do not set the olp::cache::CacheSettings::max_disk_storage value to -1, which means "No limit" and will never start data eviction.

  2. Set olp::cache::Cachesettings::eviction_policy to olp::cache::EvictionPolicy::kLeastRecentlyUsed.

    Note: The eviction only starts when the cache reaches the threshold of 95% (max_disk_storage * 0.95) and the eviction threshold reaches 10%. After the eviction, the cache size should be less or equal to 85% of max_disk_storage.

The olp::cache::EvictionPolicy::kLeastRecentlyUsed parameter works in the following way:

  • Each key from olp::cache::DefaultCache is added to the Least Recently Used (LRU) cache (if not protected).
  • The order of the entries in the LRU cache is based on how often the key is used by the user. The most recently used keys are the last candidates for eviction. The least recently used keys are the first candidates for eviction.
  • When the eviction is initiated, OCM takes the keys, which are in the back of the LRU cache, and then deletes the keys and correspondent values from the database.

Note: OCM takes as many keys as it is needed until the threshold reaches 85%.

For more information on how to manage data in the catalog version, refer to Map data consistency.

results matching ""

    No results matching ""