Class DrawableCache
Caches drawable objects per (feature, style) combination. Thread-safe: drawables are created on a background thread and read on the UI thread. Uses strict iteration-based eviction: anything not stamped with the current iteration is removed on Cleanup(long).
Inherited Members
Namespace: Mapsui.Rendering
Assembly: Mapsui.dll
Syntax
public sealed class DrawableCache : 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
Strict cleanup: removes and disposes every entry whose iteration is not
currentIteration. This ensures that features no longer
in the viewport are cleaned up immediately.
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. |