pub struct ModelCache { /* private fields */ }Expand description
LRU cache of loaded OnnxModel handles.
See the module-level docs for an end-to-end example. Keys are
canonicalised via canonical_path so equivalent relative/absolute
paths resolve to the same slot.
Implementations§
Source§impl ModelCache
impl ModelCache
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new cache with DEFAULT_CAPACITY slots.
Sourcepub fn with_capacity(capacity: usize) -> MlResult<Self>
pub fn with_capacity(capacity: usize) -> MlResult<Self>
Create a new cache with the given positive capacity.
§Errors
Returns MlError::CacheCapacityZero if capacity == 0.
Sourcepub fn get_or_load(
&self,
path: impl AsRef<Path>,
device: DeviceType,
) -> MlResult<Arc<OnnxModel>>
pub fn get_or_load( &self, path: impl AsRef<Path>, device: DeviceType, ) -> MlResult<Arc<OnnxModel>>
Load path or return the cached handle.
Under the hood the entire operation is serialised by the internal mutex, which avoids the classic double-checked-locking race where two threads both miss and both load the same model.
§Errors
Returns MlError::Pipeline with stage "cache" if the internal
mutex is poisoned, or any error produced by
OnnxModel::load on a cache miss.
Trait Implementations§
Source§impl Debug for ModelCache
impl Debug for ModelCache
Auto Trait Implementations§
impl !Freeze for ModelCache
impl RefUnwindSafe for ModelCache
impl Send for ModelCache
impl Sync for ModelCache
impl Unpin for ModelCache
impl UnsafeUnpin for ModelCache
impl UnwindSafe for ModelCache
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
Mutably borrows from an owned value. Read more
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>
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 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>
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