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 MapCache instance

    Declaration

    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 config variable and initializes the diskCache with 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.urlTemplate the substrings {z},{x}, {y} with the values of the forTilePath If {s} is defined in the template, it aplies the Round Robin algorithm.

    See also

    MapCacheConfig.roundRoubinSubdomain()

    Declaration

    Swift

    public func url(forTilePath path: MKTileOverlayPath) -> URL

    Parameters

    forTilePath

    is 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) -> String

    Parameters

    forPath

    is 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 diskCache and returns the received Data through the sucess closure. If something goes wrong it invokes the failureclosure passing the errorreturned by the system.

    Declaration

    Swift

    public func fetchTileFromServer(at path: MKTileOverlayPath,
                             failure fail: ((Error?) -> ())? = nil,
                             success succeed: @escaping (Data) -> ())

    Parameters

    at

    Path for the tile

    failure

    if the tile cannot be retrieved from the server this closure is called

    success

    if 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 the config.loadTileMode.

    See also

    LoadTileMode

    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

    DiskCache

    Declaration

    Swift

    public func calculateDiskSize() -> UInt64
  • Clears the cache. Removes all files in the diskCache As 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

    completition

    code to run upon the cache is cleared.