Class TileDrawableCache
Drawable cache for tile layers with LRU-style eviction based on render iteration. Keeps more tiles than strictly needed so that zooming in/out doesn't immediately discard previously rendered tiles.
Inherited Members
Namespace: Mapsui.Rendering
Assembly: Mapsui.dll
Syntax
public sealed class TileDrawableCache : IDrawableCache, IDisposable
Methods
| Edit this page View SourceCleanup(long)
Evicts stale cache entries. The exact strategy depends on the implementation:
- DrawableCache: removes everything not stamped with
currentIteration. - TileDrawableCache: keeps a number of extra tiles and removes the oldest by iteration.
Declaration
public void Cleanup(long currentIteration)
Parameters
| Type | Name | Description |
|---|---|---|
| long | currentIteration |
Remarks
LRU cleanup: counts the tiles stamped with currentIteration
as "active", then keeps up to 3× active (minimum 256) total entries.
Excess entries are removed oldest-iteration-first.
Clear()
Clears all cached entries and disposes them.
Declaration
public void Clear()
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Get(DrawableCacheKey, long)
Gets the drawable for a (feature, style) combination, or null if not cached.
Stamps the entry with iteration so that
Cleanup(long) knows the entry is still in use.
Declaration
public IDrawable? Get(DrawableCacheKey key, long iteration)
Parameters
| Type | Name | Description |
|---|---|---|
| DrawableCacheKey | key | The composite key of feature and style GenerationIds. |
| long | iteration | The current render iteration. |
Returns
| Type | Description |
|---|---|
| IDrawable |
ReleaseReservation(DrawableCacheKey)
Releases a reservation previously acquired via TryReserve(DrawableCacheKey). Call this in a finally block after creation completes (success or failure).
Declaration
public void ReleaseReservation(DrawableCacheKey key)
Parameters
| Type | Name | Description |
|---|---|---|
| DrawableCacheKey | key | The composite key to release. |
Set(DrawableCacheKey, IDrawable, long)
Stores a drawable for a (feature, style) combination. GenerationIds are immutable —
each combination is only ever set once. If the entry already exists it is not replaced.
The entry is stamped with iteration.
Declaration
public void Set(DrawableCacheKey key, IDrawable drawable, long iteration)
Parameters
| Type | Name | Description |
|---|---|---|
| DrawableCacheKey | key | The composite key of feature and style GenerationIds. |
| IDrawable | drawable | The drawable to cache. |
| long | iteration | The current render iteration. |
TryReserve(DrawableCacheKey)
Attempts to reserve a key for creation. If the key is already reserved by another thread (creation in progress) or already exists in the cache, returns false. Use this before creating an expensive drawable to avoid duplicate work.
Declaration
public bool TryReserve(DrawableCacheKey key)
Parameters
| Type | Name | Description |
|---|---|---|
| DrawableCacheKey | key | The composite key of feature and style GenerationIds. |
Returns
| Type | Description |
|---|---|
| bool | True if the reservation was successful; false if already reserved or cached. |