Interface IDrawableCache
Interface for caches that store pre-created drawable objects per (feature, style) combination. Different implementations can use different eviction strategies (e.g. strict iteration-based for regular layers, LRU for tile layers). Each entry is stamped with the iteration at which it was last used.
Inherited Members
Namespace: Mapsui.Rendering
Assembly: Mapsui.dll
Syntax
public interface 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
void Cleanup(long currentIteration)
Parameters
| Type | Name | Description |
|---|---|---|
| long | currentIteration |
Clear()
Clears all cached entries and disposes them.
Declaration
void Clear()
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
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
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
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
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. |