MapCache
open class MapCache : MapCacheProtocol
This is the main implementation of the MapCacheProtocol, the actual cache
-
Cofiguration that will be used to set up the behavior of the
MapCacheinstanceDeclaration
Swift
public var config: MapCacheConfig -
It manages the physical storage of the tile images in the device
Declaration
Swift
public var diskCache: DiskCache -
Manages the queue of network requests for retrieving the tiles
Declaration
Swift
let operationQueue: OperationQueue -
Constructor. It sets the
configvariable and initializes thediskCachewith the name and capacity set in the config.Declaration
Swift
public init(withConfig config: MapCacheConfig) -
Returns the URL for a tile.
Basically replaces in
config.urlTemplatethe substrings{z},{x},{y}with the values of theforTilePathIf{s}is defined in the template, it aplies the Round Robin algorithm.See also
MapCacheConfig.roundRoubinSubdomain()
Declaration
Swift
public func url(forTilePath path: MKTileOverlayPath) -> URLParameters
forTilePathis the path for the tile in (x, y, z) tile coordinates.
-
For the path passed as argument it creates a unique key to be used in
DiskCache.The output is a string that has the following format
{config.urlTemplate}-{x}-{y}-{z}where:- config.urlTemplate is the template url template and
x, y and z are the coords of the path
Declaration
Swift
public func cacheKey(forPath path: MKTileOverlayPath) -> StringParameters
forPathis the path of the tile you want the cache
-
Fetches tile from server. It resolves the url for the tile at the path. Then it tries to download the tile image from the server. If everything goes ok it and updates the image in
diskCacheand returns the receivedDatathrough thesucessclosure. If something goes wrong it invokes thefailureclosure passing theerrorreturned by the system.Declaration
Swift
public func fetchTileFromServer(at path: MKTileOverlayPath, failure fail: ((Error?) -> ())? = nil, success succeed: @escaping (Data) -> ())Parameters
atPath for the tile
failureif the tile cannot be retrieved from the server this closure is called
successif the image is downloaded
-
Returns the tile to be displayed on the overlay. The strategy used to retrieve the tile (i.e. from network or from the
diskCache) depends on theconfig.loadTileMode.See also
Declaration
Swift
public func loadTile(at path: MKTileOverlayPath, result: @escaping (Data?, Error?) -> Void) -
Currently size of the cache
Declaration
Swift
public var diskSize: UInt64 { get } -
Calculates the disk space allocated in dis for the cache
See also
DiskCacheDeclaration
Swift
public func calculateDiskSize() -> UInt64 -
Clears the cache. Removes all files in the
diskCacheAs it may take some time to remove all files it calls the completition closure upon finishing the removal.Declaration
Swift
public func clear(completition: (() -> ())?)Parameters
completitioncode to run upon the cache is cleared.
View on GitHub
MapCache Class Reference