Skip to main content

ModelRegistry

Struct ModelRegistry 

Source
pub struct ModelRegistry<T> { /* private fields */ }
Expand description

Shared resident model registry with weighted LRU eviction.

Implementations§

Source§

impl<T> ModelRegistry<T>

Source

pub fn new(config: RegistryConfig) -> Self

Source

pub fn config(&self) -> &RegistryConfig

Source

pub fn total_weight(&self) -> u64

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn insert( &self, key: LoadKey, value: Arc<T>, weight: ResidencyWeight, ) -> Result<Arc<RegistryEntry<T>>>

Insert or refresh an entry. Evicts idle entries if needed.

New inserts start with active_refs == 0. Prefer Self::insert_and_pin when the caller will immediately use the value (JOE-1646).

Source

pub fn insert_and_pin( &self, key: LoadKey, value: Arc<T>, weight: ResidencyWeight, ) -> Result<RegistryPin<T>>

Insert (or refresh) and return a pin under one lock — no eviction window between publication and active lease (JOE-1646).

Source

pub fn get(&self, key: &LoadKey) -> Option<Arc<RegistryEntry<T>>>

Source

pub fn pin(&self, key: &LoadKey) -> Option<RegistryPin<T>>

Pin for an active operation (prevents eviction).

Prefer Self::get_and_pin when the caller needs the value only while pinned (atomic lookup+lease).

Source

pub fn get_and_pin(&self, key: &LoadKey) -> Option<RegistryPin<T>>

Atomic lookup + pin under the registry lock (JOE-1646).

There is no window where the entry can be evicted after the caller has observed it but before active_refs is incremented.

Source

pub fn clear_idle(&self) -> (usize, usize)

Drop idle entries only (JOE-1646 third-pass).

Entries with active_refs > 0 or pinned stay in the map with their weight so residency accounting remains truthful and a same-key reload cannot multiply native sessions while an operation still holds a pin.

Returns (removed, retained_active).

Source

pub fn clear(&self)

Alias for Self::clear_idle — never forcibly drops active leases.

Source

pub fn try_unload(&self, key: &LoadKey) -> bool

Remove a specific key if not active.

Source

pub fn snapshot(&self) -> Vec<RegistrySnapshot>

Auto Trait Implementations§

§

impl<T> !Freeze for ModelRegistry<T>

§

impl<T> RefUnwindSafe for ModelRegistry<T>

§

impl<T> Send for ModelRegistry<T>
where T: Sync + Send,

§

impl<T> Sync for ModelRegistry<T>
where T: Sync + Send,

§

impl<T> Unpin for ModelRegistry<T>

§

impl<T> UnsafeUnpin for ModelRegistry<T>

§

impl<T> UnwindSafe for ModelRegistry<T>

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more