Skip to main content

ArtifactCache

Struct ArtifactCache 

Source
pub struct ArtifactCache { /* private fields */ }
Expand description

In-memory artifact cache implementation.

This is a simple implementation suitable for lab scenarios and testing. Production usage would typically integrate with more sophisticated cache backends and persistence layers.

Implementations§

Source§

impl ArtifactCache

Source

pub fn new(config: ArtifactCacheConfig) -> Self

Create a new artifact cache with the given configuration.

Source

pub fn default_config() -> Self

Create a cache with default configuration.

Source

pub fn memory_pressure_snapshot( &self, now_nanos: u64, ) -> ArtifactMemoryPressureSnapshot

Take a memory pressure snapshot of the current cache state.

now_nanos must use the same clock domain as timestamps supplied to Self::put, Self::get, and Self::invalidate_expired. Keeping the clock explicit makes lab replay deterministic and prevents Unix timestamps from being compared with process-relative monotonic time.

Source

pub fn contains(&self, id: &str) -> bool

Check if an artifact is cached.

Source

pub const fn statistics(&self) -> &CacheStatistics

Get current cache statistics.

Source

pub const fn config(&self) -> &ArtifactCacheConfig

Get current cache configuration.

Source

pub fn len(&self) -> usize

Get the current number of cached artifacts.

Source

pub fn is_empty(&self) -> bool

Check if the cache is empty.

Source

pub const fn current_size_bytes(&self) -> u64

Get the current total size of cached artifacts.

Source

pub fn get(&mut self, id: &str, now_nanos: u64) -> Option<&[u8]>

Retrieve a cached artifact by ID at now_nanos in the cache clock domain. Returns None if the artifact is not cached or has expired.

Source

pub fn put(&mut self, id: String, data: Vec<u8>, now_nanos: u64) -> bool

Store an artifact at now_nanos in the cache clock domain. Returns true if successfully cached, false if eviction failed to make space.

Source

pub fn remove(&mut self, id: &str) -> bool

Remove a specific artifact from the cache. Returns true if the artifact was removed, false if it didn’t exist.

Source

pub fn evict(&mut self, target_bytes: u64) -> u32

Evict artifacts based on the configured eviction policy. Returns the number of artifacts evicted.

Source

pub fn invalidate_expired(&mut self, now_nanos: u64) -> u32

Remove all expired artifacts from the cache. Returns the number of artifacts invalidated.

Source

pub fn clear(&mut self)

Clear all artifacts from the cache.

Trait Implementations§

Source§

impl Debug for ArtifactCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V