TileCache

Two-level cache for map tiles: in-memory LRU cache backed by persistent disk cache.

Memory cache holds up to 1/8 of available heap memory for fast access. The tile caches of all maps with a disk cache share one memory cache, with the tiles of each namespace kept apart. So a map shown again, e.g. in a tab or a list, draws its tiles from the first frame on, instead of waiting for them to be read from disk. put also writes the tile to the disk cache, so call it from a background thread. Disk cache stores up to 50MB of tiles to reduce network requests across app restarts.

A tile older than the disk cache's maximum age is only returned by getStale, as a fallback when a fresh download failed. It is then marked as stale (see isStale) until a fresh tile is put.

Parameters

context

Context for the disk cache, or null for a memory-only cache of its own

namespace

Disk cache namespace, e.g. the tile source, so tiles of different sources are stored separately

Constructors

Link copied to clipboard
constructor(context: Context? = null, namespace: String = DiskTileCache.DEFAULT_NAMESPACE)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun clear()
Link copied to clipboard
fun close()
Link copied to clipboard

Returns the tile from memory (which may be stale, see isStale), or a fresh tile from disk.

Link copied to clipboard
Link copied to clipboard

Returns the tile even if its disk entry has expired, for use when downloading a fresh tile failed (e.g. offline). An expired tile is promoted to memory and marked as stale.

Link copied to clipboard

Returns true if the tile in the memory cache is an expired one from getStale, which should be replaced by a fresh download.

Link copied to clipboard
fun put(tile: TileCoordinate, bitmap: Bitmap, bytes: ByteArray? = null)

Puts the tile into the memory cache and the disk cache.