pub struct TileCache { /* private fields */ }Expand description
A fixed-capacity LRU in-memory tile cache.
See the module-level documentation for eviction policy, lifecycle, and complexity details.
Implementations§
Source§impl TileCache
impl TileCache
Sourcepub fn new(max_entries: usize) -> Self
pub fn new(max_entries: usize) -> Self
Create a new cache with the given maximum capacity.
A max_entries of 0 is valid but degenerate – every insertion
is immediately evicted. Typical values range from 100 (low
memory) to 1000+ (large-screen / high-zoom).
Sourcepub fn with_byte_budget(max_entries: usize, max_bytes: usize) -> Self
pub fn with_byte_budget(max_entries: usize, max_bytes: usize) -> Self
Create a cache with both an entry-count and a byte-budget limit.
Eviction triggers when either limit is exceeded.
Sourcepub fn get(&self, id: &TileId) -> Option<&TileCacheEntry>
pub fn get(&self, id: &TileId) -> Option<&TileCacheEntry>
Look up a tile in the cache.
Returns None if the tile has never been inserted or has been
evicted. Does not update the LRU order (read-only).
Sourcepub fn contains(&self, id: &TileId) -> bool
pub fn contains(&self, id: &TileId) -> bool
Returns true if the tile is present (in any state).
Sourcepub fn total_bytes(&self) -> usize
pub fn total_bytes(&self) -> usize
Total payload bytes currently tracked in the cache.
Sourcepub fn pending_ids(&self) -> Vec<TileId>
pub fn pending_ids(&self) -> Vec<TileId>
Return the IDs of all pending tiles currently in the cache.
Sourcepub fn inflight_ids(&self) -> Vec<TileId>
pub fn inflight_ids(&self) -> Vec<TileId>
Return the IDs of all tiles that are actively pending or reloading.
Sourcepub fn expired_ids_at(&self, now: SystemTime) -> Vec<TileId>
pub fn expired_ids_at(&self, now: SystemTime) -> Vec<TileId>
Return the IDs of all tiles that are stale and eligible for refresh at now.
Sourcepub fn expired_ids(&self) -> Vec<TileId>
pub fn expired_ids(&self) -> Vec<TileId>
Return the IDs of all tiles that are stale and eligible for refresh now.
Sourcepub fn stats(&self) -> TileCacheStats
pub fn stats(&self) -> TileCacheStats
Return a state-count snapshot of the cache contents.
Sourcepub fn touch(&mut self, id: &TileId) -> bool
pub fn touch(&mut self, id: &TileId) -> bool
Mark an existing entry as recently used (O(1)).
Returns true if the tile was present and moved to the MRU end.
Sourcepub fn insert_pending_with_eviction(
&mut self,
id: TileId,
) -> InsertPendingResult
pub fn insert_pending_with_eviction( &mut self, id: TileId, ) -> InsertPendingResult
Insert a Pending entry for id and report
any evictions that occurred.
Sourcepub fn insert_pending(&mut self, id: TileId) -> bool
pub fn insert_pending(&mut self, id: TileId) -> bool
Insert a Pending entry for id.
Returns true if the entry was newly inserted.
Sourcepub fn promote_with_eviction(
&mut self,
id: TileId,
response: TileResponse,
) -> Vec<EvictedTile>
pub fn promote_with_eviction( &mut self, id: TileId, response: TileResponse, ) -> Vec<EvictedTile>
Promote an entry to Loaded and move
it to the most-recently-used position, reporting any evicted tiles.
Sourcepub fn promote(&mut self, id: TileId, response: TileResponse)
pub fn promote(&mut self, id: TileId, response: TileResponse)
Promote an entry to Loaded and move
it to the most-recently-used position.
Sourcepub fn mark_expired(&mut self, id: TileId) -> bool
pub fn mark_expired(&mut self, id: TileId) -> bool
Mark a loaded tile as expired while keeping it renderable.
Sourcepub fn start_reload(&mut self, id: TileId) -> bool
pub fn start_reload(&mut self, id: TileId) -> bool
Transition a stale tile into reloading while retaining its old payload.
Sourcepub fn refresh_ttl(&mut self, id: TileId, freshness: TileFreshness) -> bool
pub fn refresh_ttl(&mut self, id: TileId, freshness: TileFreshness) -> bool
Refresh the TTL of a reloading/expired entry without replacing its payload.
This is the cache-side handler for 304 Not Modified responses.
Sourcepub fn revalidation_hint(&self, id: &TileId) -> Option<RevalidationHint>
pub fn revalidation_hint(&self, id: &TileId) -> Option<RevalidationHint>
Return the revalidation hint (etag + last-modified) for a tile.
Sourcepub fn mark_failed(&mut self, id: TileId, error: &TileError)
pub fn mark_failed(&mut self, id: TileId, error: &TileError)
Mark the tile as failed, preserving stale renderable payload when possible.
Sourcepub fn cancel_reload(&mut self, id: &TileId) -> bool
pub fn cancel_reload(&mut self, id: &TileId) -> bool
Cancel an in-flight reload, demoting the entry back to Expired
while preserving its renderable payload.
Returns true if the entry was Reloading and was demoted.
Has no effect on entries in any other state.