Interface OfflineCacheManager

com.yandex.mapkit.offline_cache

public interface OfflineCacheManager

Attention.

This feature is not available in the free MapKit version.

Offline cache manager.

There are a number of asynchronous operations that shouldn't be executed simultaneously. When multiple operations from the following list are executed in parallel- there's no guarantee that they will take effect in the order they were issued: OfflineCacheManager#computeCacheSize(SizeListener)OfflineCacheManager#clear(ClearListener)OfflineCacheManager#moveData(String- DataMoveListener) Region#drop() Region#start()

Nested Classes

Methods

void addListener(@NonNull OfflineCacheManagerListener managerListener)

Subscribes a listener for "download status" events.

void addStorageErrorListener(@NonNull StorageErrorListener errorListener)

Subscribes the listener to storage error events.

void allowUseCellularNetwork(boolean useCellular)

Indicates whether to allow downloading using cellular networks (3G, LTE, etc.) Disallowed by default.

void clear(@NonNull ClearListener callback)

Erases all data for downloads and regions and wipes the tile cache.

void computeCacheSize(@NonNull SizeListener callback)

Calculates the full cache size in bytes.

void enableAutoUpdate(boolean enable)

Enables autoupdating downloaded caches when they become outdated.

List< Region > filterRegions(@NonNull String filter)

Returns a filtered list of regions.

boolean isValid()

Tells if this OfflineCacheManager is valid or no.

void moveData(@NonNull String newPath, @NonNull DataMoveListener dataMoveListener)

Moves offline caches to the specified folder.

List< Region > regions()

Returns a list of regions.

void removeListener(@NonNull OfflineCacheManagerListener managerListener)

Unsubscribes the listener from manager events.

void removeStorageErrorListener(@NonNull StorageErrorListener errorListener)

Unsubscribes the error listener from storage error events.

void requestPath(@NonNull PathGetterListener callback)

Provides the data path for offline cache files.

void setCachePath(@NonNull String path)

Sets a new path for caches.

Method Detail

addListener

public void addListener (@NonNull OfflineCacheManagerListener managerListener)

Subscribes a listener for "download status" events.

The listener will receive the onListUpdated callback asynchronously after the call.
Parameters:
managerListener

Listener that will receive the events.

addStorageErrorListener

public void addStorageErrorListener (@NonNull StorageErrorListener errorListener)

Subscribes the listener to storage error events.

Parameters:
errorListener

Listener that will receive storage error events.

allowUseCellularNetwork

public void allowUseCellularNetwork (boolean useCellular)

Indicates whether to allow downloading using cellular networks (3G, LTE, etc.) Disallowed by default.

clear

public void clear (@NonNull ClearListener callback)

Erases all data for downloads and regions and wipes the tile cache.

Forces reloading the list from the remote source.

computeCacheSize

public void computeCacheSize (@NonNull SizeListener callback)

Calculates the full cache size in bytes.

enableAutoUpdate

public void enableAutoUpdate (boolean enable)

Enables autoupdating downloaded caches when they become outdated.

filterRegions

public List< Region > filterRegions (@NonNull String filter)

Returns a filtered list of regions.

The filtered list is a subset of the full list of regions. Note that if the full list of regions is not ready yet, then the returned list of filtered regions will be empty. The list will also be empty if there aren't any regions that match the 'filter' expression.

isValid

public boolean isValid ()

Tells if this OfflineCacheManager is valid or no.

Any other method (except for this one) called on an invalid OfflineCacheManager will throw java.lang.RuntimeException. An instance becomes invalid only on UI thread, and only when its implementation depends on objects already destroyed by now. Please refer to general docs about the interface for details on its invalidation.

moveData

public void moveData (@NonNull String newPath, @NonNull DataMoveListener dataMoveListener)

Moves offline caches to the specified folder.

This operation is non-cancellable. If there is already a pending operation to set the cache path, it throws an error (Android). If the application exits before the operation is completed, it does not take effect, but garbage will not be cleared.
Parameters:
newPath

New path to store data.

dataMoveListener

It will be unsubscribed automatically when the operation is completed or fails with an error.

regions

public List< Region > regions ()

Returns a list of regions.

An empty list indicates that the list is still loading. When it is ready, onListUpdated event will be called with the added/removed regions.

removeListener

public void removeListener (@NonNull OfflineCacheManagerListener managerListener)

Unsubscribes the listener from manager events.

Does nothing if the listener was not subscribed.
Parameters:
managerListener

Listener to unsubscribe.

removeStorageErrorListener

public void removeStorageErrorListener (@NonNull StorageErrorListener errorListener)

Unsubscribes the error listener from storage error events.

Does nothing if the error listener was not subscribed.
Parameters:
errorListener

Listener to unsubscribe.

requestPath

public void requestPath (@NonNull PathGetterListener callback)

Provides the data path for offline cache files.

setCachePath

public void setCachePath (@NonNull String path)

Sets a new path for caches.

If the specified path contains an existing cache, this cache will be used; otherwise, a new cache will be initialized. This takes effect after the application is restarted.