pub struct MeshCache { /* private fields */ }Expand description
Thread-safe LRU mesh cache.
Stores generated meshes keyed by SDF tree hash, bounds, and resolution.
Uses RwLock internally so multiple readers can access the cache
concurrently, while writes (insert/evict) take exclusive access.
Implementations§
Source§impl MeshCache
impl MeshCache
Sourcepub fn new(config: CacheConfig) -> Self
pub fn new(config: CacheConfig) -> Self
Create a new mesh cache with the given configuration.
Sourcepub fn get(&self, key: &MeshCacheKey) -> Option<Arc<Mesh>>
pub fn get(&self, key: &MeshCacheKey) -> Option<Arc<Mesh>>
Get a cached mesh by key. Returns None if not cached.
This promotes the entry to most-recently-used position.
Sourcepub fn insert(&self, key: MeshCacheKey, mesh: Mesh) -> Arc<Mesh> ⓘ
pub fn insert(&self, key: MeshCacheKey, mesh: Mesh) -> Arc<Mesh> ⓘ
Insert a mesh into the cache, evicting the oldest entry if full.
Returns an Arc<Mesh> pointing to the cached copy.
Sourcepub fn memory_usage(&self) -> usize
pub fn memory_usage(&self) -> usize
Total approximate memory usage of all cached meshes in bytes.
Sourcepub fn get_or_generate<F>(&self, key: MeshCacheKey, generator: F) -> Arc<Mesh> ⓘ
pub fn get_or_generate<F>(&self, key: MeshCacheKey, generator: F) -> Arc<Mesh> ⓘ
Get a cached mesh or generate it using the provided closure.
If the key is found in the cache, returns the cached Arc<Mesh>.
Otherwise, calls generator() to produce a new mesh, inserts it
into the cache, and returns it.
Note: The generator is called outside the lock to avoid holding the lock during potentially expensive mesh generation.
Auto Trait Implementations§
impl !Freeze for MeshCache
impl RefUnwindSafe for MeshCache
impl Send for MeshCache
impl Sync for MeshCache
impl Unpin for MeshCache
impl UnsafeUnpin for MeshCache
impl UnwindSafe for MeshCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more