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
impl SceneCache
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Creates a cache with at most this many retained entries; zero disables it.
Sourcepub fn with_limits(limits: CacheLimits) -> Self
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.
Sourcepub fn max_bytes(&self) -> usize
pub fn max_bytes(&self) -> usize
Logical payload allowance; usize::MAX means no configured byte bound.
Sourcepub fn retained_bytes(&self) -> usize
pub fn retained_bytes(&self) -> usize
Sum of the declared charges for currently retained entries.
Sourcepub 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> ⓘ
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.