Skip to main content

TileCache

Struct TileCache 

Source
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

Source

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).

Source

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.

Source

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).

Source

pub fn contains(&self, id: &TileId) -> bool

Returns true if the tile is present (in any state).

Source

pub fn len(&self) -> usize

Number of entries currently in the cache.

Source

pub fn is_empty(&self) -> bool

Whether the cache is empty.

Source

pub fn capacity(&self) -> usize

Maximum capacity configured at construction time.

Source

pub fn total_bytes(&self) -> usize

Total payload bytes currently tracked in the cache.

Source

pub fn max_bytes(&self) -> Option<usize>

The byte budget, if configured.

Source

pub fn pending_ids(&self) -> Vec<TileId>

Return the IDs of all pending tiles currently in the cache.

Source

pub fn inflight_ids(&self) -> Vec<TileId>

Return the IDs of all tiles that are actively pending or reloading.

Source

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.

Source

pub fn expired_ids(&self) -> Vec<TileId>

Return the IDs of all tiles that are stale and eligible for refresh now.

Source

pub fn stats(&self) -> TileCacheStats

Return a state-count snapshot of the cache contents.

Source

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.

Source

pub fn insert_pending_with_eviction( &mut self, id: TileId, ) -> InsertPendingResult

Insert a Pending entry for id and report any evictions that occurred.

Source

pub fn insert_pending(&mut self, id: TileId) -> bool

Insert a Pending entry for id.

Returns true if the entry was newly inserted.

Source

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.

Source

pub fn promote(&mut self, id: TileId, response: TileResponse)

Promote an entry to Loaded and move it to the most-recently-used position.

Source

pub fn mark_expired(&mut self, id: TileId) -> bool

Mark a loaded tile as expired while keeping it renderable.

Source

pub fn start_reload(&mut self, id: TileId) -> bool

Transition a stale tile into reloading while retaining its old payload.

Source

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.

Source

pub fn revalidation_hint(&self, id: &TileId) -> Option<RevalidationHint>

Return the revalidation hint (etag + last-modified) for a tile.

Source

pub fn mark_failed(&mut self, id: TileId, error: &TileError)

Mark the tile as failed, preserving stale renderable payload when possible.

Source

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.

Source

pub fn remove(&mut self, id: &TileId) -> bool

Remove a tile from the cache (O(1)).

Returns true if the tile was present and removed.

Source

pub fn clear(&mut self)

Remove all entries from the cache.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.