Skip to main content

SceneCache

Struct SceneCache 

Source
pub struct SceneCache { /* private fields */ }
Expand description

Shared LRU storage for pure authoring computations, with optional byte accounting.

Values must depend only on their keys and immutable resources. Resource revisions belong in the key. The default retains 256 entries without a byte cap. with_limits adds a caller-declared logical byte allowance for cache_with_cost. Ordinary cache() is entry-bounded only and reports no retained-byte charge. Outstanding Arc pins and allocator overhead are not bounded. Concurrent misses may compute more than once; builders and cost callbacks run outside the lock. Zero entries disable retention; zero bytes disable costed values. Original keys are retained and compared by type and equality after hashing.

Implementations§

Source§

impl SceneCache

Source

pub fn new(capacity: usize) -> Self

Creates a cache with at most this many retained entries; zero disables it.

Source

pub fn with_limits(limits: CacheLimits) -> Self

Bounds entries and caller-declared retained payload bytes. Heap-owning keys and values need SceneContext::cache_with_cost for payload charges. Neither allocator overhead nor externally pinned Arc values are bounded.

Source

pub fn max_bytes(&self) -> usize

Logical payload allowance; usize::MAX means no configured byte bound.

Source

pub fn retained_bytes(&self) -> usize

Sum of the declared charges for currently retained entries.

Source

pub fn capacity(&self) -> usize

Maximum number of retained entries, not a byte budget.

Source

pub fn len(&self) -> usize

Number of currently retained entries.

Source

pub fn is_empty(&self) -> bool

Whether no computed values are currently retained.

Source

pub fn clear(&self)

Removes retained entries without invalidating existing returned handles.

Source

pub fn get_with_cost<Key: Eq + Hash + Send + Sync + 'static, Value: Send + Sync + 'static>( &self, key: Key, build: impl FnOnce() -> Value, cost: impl FnOnce(&Value) -> usize, ) -> Arc<Value> ⓘ

Gets a pure computed value with a caller-declared retained payload charge.

Source

pub fn lookup<Key: Eq + Hash + Send + Sync + 'static, Value: Send + Sync + 'static>( &self, key: &Key, ) -> Option<Arc<Value>>

Looks up a renderer content key independently of the caller’s source location.

Source

pub fn insert_with_cost<Key: Eq + Hash + Send + Sync + 'static, Value: Send + Sync + 'static>( &self, key: Key, value: Value, cost: impl FnOnce(&Value) -> usize, ) -> Arc<Value> ⓘ

Inserts checked pure content, converging concurrent inserts to the retained value.

Trait Implementations§

Source§

impl Debug for SceneCache

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SceneCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.