TileCache

class TileCache<DataType : TileData>(val sourceID: String = "")

A TileCache is a cache of tiles that are currently in use by the map. It is used to keep track of which tiles are currently in use, which tiles are pending, and which tiles are stale.

Constructors

Link copied to clipboard
constructor(sourceID: String = "")

Types

Link copied to clipboard
object Companion

Process-wide GPU/native bookkeeping shared by every TileCache instance: the shared textureUnits pool, bind-slot recycling, and the global per-frame GPU bind budget. Kept here rather than per-instance because texture units are a single scarce GPU resource shared across all layers/sources, and must survive across MapView instances in the same process.

Properties

Link copied to clipboard

Tile×time entries currently awaiting a download response, keyed by coordinate hash. See setPending/setPendingKey/isPending; entries here (and in bindList) mark a key as in-flight so isInFlight can veto eviction until the response arrives and it is bound.

Link copied to clipboard

Timestamp each _pending entry was marked pending, set/cleared alongside it in setPending/setPendingKey.

Link copied to clipboard

Tiles for zoom levels below _persistentLevelCount that are never subject to LRU eviction, kept separate from tiles so low-zoom/overview tiles always stay resident.

Link copied to clipboard

Coordinate-hash -> request-timestamp map marking a tile as having an in-flight download requested (set by TilePyramid when a request is issued). Cleared as soon as the tile is bound or otherwise resolved, so a stale entry does not permanently block re-requesting it.

Link copied to clipboard

Coordinate hashes flagged as stale (e.g. needing a refresh) via setStale; queried by isStale.

Link copied to clipboard

Coordinate hashes of tiles queued for GPU upload, drained by bindTextures. Sources add to this set once a tile's data is ready to bind; isInFlight treats membership as in-flight so eviction leaves the entry alone until it is actually bound (or dropped if the underlying cache entry vanishes first).

Link copied to clipboard

Current total tile count: tiles plus the (currently zero, since _persistentLevelCount is 0) persistent-level capacity.

Link copied to clipboard

Reserved for a future tile snapshot; currently never initialized or assigned.

Link copied to clipboard
val count: Int

Number of tiles currently in tiles.

Link copied to clipboard
val hashList: <Error class: unknown class><String, MutableList<String>>

Coordinate hash to list-of-hashes lookup; currently unused elsewhere in the codebase.

Link copied to clipboard
val hashMap: <Error class: unknown class>

Coordinate hash -> bound GL texture-unit id, maintained by bindTextures and consumed by rendering to look up which texture holds a given tile.

Link copied to clipboard

Coordinate hashes of every tile currently in tiles.

Link copied to clipboard

Tiles bucketed by zoom level; populated by updateTile and pruned by removeTile.

Link copied to clipboard

Fraction (0–1) of Runtime.maxMemory currently used by the JVM heap, refreshed by memoryLog each time bindCount changes.

Link copied to clipboard
val nativeCache: NativeLibCache

This cache's handle to the native pixel store, namespaced by sourceID so different sources' tiles never collide.

Link copied to clipboard

Number of tile×time entries currently awaiting a download response (size of _pending).

Link copied to clipboard

GL texture-unit indices queued for deletion; drained a few at a time inside bindTextures (see maxDeletesPerCall) so a large batch of deletes does not stall a single frame.

Link copied to clipboard
Link copied to clipboard

Number of coordinate hashes currently flagged stale (size of _stale).

Link copied to clipboard

The LRU-backed store of non-persistent tiles, keyed by tile-coordinate hash. Capacity comes from defaultCacheCapacity. Eviction is disabled while Timeline.isGloballyPlaying or Timeline.holdFullTimelineResidency holds so a full playback range stays resident, and a removed entry's native/GPU pixels are freed here unless that same play/hold state (or a deliberate viewport-change eviction via forceNativeFreeOnRemove) says otherwise.

Functions

Link copied to clipboard
fun bindTextures(sourceId: String? = null): <Error class: unknown class><String, Int>

Called from LayerHost.

Link copied to clipboard
fun cleanup()

Deletes the shared textureUnits GL texture names, releasing this cache's GPU texture pool.

Link copied to clipboard
fun clearOutsideBounds(bounds: TileBounds?, clearNative: Boolean = true)

Removes every cached tile whose coordinate falls outside bounds (wrong zoom, or x/y outside the given range) and is not currently in-flight, letting onRemove own the actual native/GPU cleanup. No-op if bounds is null.

Link copied to clipboard

True if coord is already cached, checking _persistents for persistent zoom levels and tiles otherwise.

Link copied to clipboard
fun evictTilesOutsideViewport(visibleHashShorts: Set<String>, protectedAncestorHashShorts: Set<String> = emptySet())

Evicts every cached tile×time whose tile coordinate (x/y/z, ignoring interval) is not in visibleHashShorts and is not a protected zoom-ancestor of one (protectedAncestorHashShorts) — i.e., belongs to a viewport panned away from. Deliberately runs regardless of play state (unlike evictTimesNotIn): rule 7's "never evict" is about the currently visible tiles' full timeline, not every viewport ever visited during a session. Without this, GPU/native memory for stale viewports never comes back, growing unbounded until downloads stall and rendering has no headroom left to animate.

Link copied to clipboard
fun evictTimesNotIn(keepTimes: Set<String>)

Drops cached tile×time entries whose interval is outside the active playback keep-set. Call when the global timeline phase advances so long playback does not retain every interval visited so far (native ~1MB + GL texture per tile×time).

Link copied to clipboard

Apply onRemove GPU bookkeeping on the GL thread (hashMap + bind-slot recycle).

Link copied to clipboard
operator fun get(coord: TileCoord): Tile<DataType>?

Looks up the cached Tile for coord (persistent levels or tiles), or null if not cached.

Link copied to clipboard

True when this tile×time can be uploaded (or is already on the GPU). A bare tiles entry or TileList.readyList claim is not enough — those can outlive lost pixels and then permanently skip HTTP while buildReadyPlaybackList never sees a texture.

Link copied to clipboard

True if coord currently has an in-flight download tracked in _pending.

Link copied to clipboard

True if tile is currently flagged stale in _stale.

Link copied to clipboard

Generates the shared textureUnits GL texture names once per EGL context. Safe to call repeatedly: a no-op if hasInitialized is already true for the current context, but detects an EGL context switch (e.g. a second MapView/activity) via object identity against textureContext and regenerates + resets the shared bind bookkeeping in that case, since texture names from the old context are meaningless (or worse, colliding) in the new one.

Link copied to clipboard

Re-inserts a shell Tile when nativeCache/GPU still has pixels for hash (per hasBindableEncodedPixels) but the entry is missing from tiles/_persistents — e.g. the LRU evicted it — so bindTextures can restore EncodedData.paddedData without another HTTP request. Returns true if the tile is bindable (whether or not a shell needed inserting).

Link copied to clipboard
fun removeAll()

Clears every entry from tiles (does not touch _persistents).

Link copied to clipboard
operator fun set(coord: TileCoord, tile: Tile<DataType>?)

Stores tile under coord via updateTile, or removes any cached entry for coord if tile is null.

Link copied to clipboard
fun setPending(isPending: Boolean, tile: Tile<DataType>)

Marks or clears tile as pending in _pending/_pendingTime, keyed by its own Tile.coordHash. See setPendingKey for marking an arbitrary hash without a Tile instance.

Link copied to clipboard
fun setPendingKey(isPending: Boolean, key: String, placeholder: Tile<DataType>)

Marks or clears the pending flag for an arbitrary hash key, independent of a specific Tile instance. A multi-interval batch request marks only one "representative" tile pending, and that flag clears the moment the HTTP response arrives — well before the other intervals in the batch have been decoded, edge-blended, and queued to bind. Until this per-interval flag is set too, isInFlight sees those other intervals as safe to drop, so a concurrent clearOutsideBounds or evictTimesNotIn sweep can strand one before it is ever bound. placeholder is never read back — only key presence matters to pending/in-flight checks.

Link copied to clipboard
fun setStale(isStale: Boolean, tile: Tile<DataType>)

Marks or clears tile as stale in _stale, keyed by its Tile.coordHash.

Link copied to clipboard

Convenience overload of updateTile that stores tile under its own Tile.coord.

fun updateTile(tile: Tile<DataType>, coord: TileCoord)

Stores tile in _persistents (for zoom levels below _persistentLevelCount) or tiles otherwise, keyed by coord/tile.coordHash, and ensures a bucket for coord's zoom exists in levels.