Skip to main content

MeshCache

Struct MeshCache 

Source
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

Source

pub fn new(config: CacheConfig) -> Self

Create a new mesh cache with the given configuration.

Source

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.

Source

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.

Source

pub fn remove(&self, key: &MeshCacheKey) -> Option<Arc<Mesh>>

Remove an entry from the cache.

Source

pub fn clear(&self)

Clear all cached meshes.

Source

pub fn len(&self) -> usize

Number of cached entries.

Source

pub fn is_empty(&self) -> bool

Check if the cache is empty.

Source

pub fn memory_usage(&self) -> usize

Total approximate memory usage of all cached meshes in bytes.

Source

pub fn get_or_generate<F>(&self, key: MeshCacheKey, generator: F) -> Arc<Mesh> ⓘ
where F: FnOnce() -> 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§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.