pub struct InventoryCache { /* private fields */ }Expand description
In-memory inventory cache with a freshness window (design D2).
Owned by the supervisor’s sweep loop: the sweep stores a fresh snapshot at
its cadence, and /tell / /agents reuse the cached snapshot while it is
younger than max_age, rebuilding on demand only when stale. There is no
on-disk cache — a supervisor restart produces a fresh inventory.
Implementations§
Source§impl InventoryCache
impl InventoryCache
Sourcepub fn from_seconds(seconds: u64) -> Self
pub fn from_seconds(seconds: u64) -> Self
Creates an empty cache with a freshness window in seconds (the
[supervisor.tell] inventory_max_age_seconds config value).
Sourcepub fn snapshot(&self) -> Option<&AgentInventory>
pub fn snapshot(&self) -> Option<&AgentInventory>
The cached snapshot, if any.
Sourcepub fn is_fresh_at(&self, now: Instant) -> bool
pub fn is_fresh_at(&self, now: Instant) -> bool
Whether the cache holds a snapshot still within max_age as of now.
Sourcepub fn store(&mut self, snapshot: AgentInventory)
pub fn store(&mut self, snapshot: AgentInventory)
Stores a freshly-built snapshot (called by the sweep loop).
Sourcepub fn get_or_refresh<F, E>(
&mut self,
now: Instant,
refresh: F,
) -> Result<&AgentInventory, E>
pub fn get_or_refresh<F, E>( &mut self, now: Instant, refresh: F, ) -> Result<&AgentInventory, E>
Returns the cached snapshot when fresh as of now; otherwise calls
refresh to rebuild it, stores the result, and returns it.
refresh is invoked at most once per stale lookup, so rapid
consecutive /agents within the freshness window trigger only one
rebuild (the broker is not re-polled while the snapshot is fresh).
§Errors
Propagates any error from refresh; the previous snapshot (if any) is
left untouched on failure.
§Panics
Does not panic in practice: when the cache is stale refresh populates
the snapshot before it is unwrapped, so the Some invariant holds.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for InventoryCache
impl RefUnwindSafe for InventoryCache
impl Send for InventoryCache
impl Sync for InventoryCache
impl Unpin for InventoryCache
impl UnsafeUnpin for InventoryCache
impl UnwindSafe for InventoryCache
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<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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