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
impl ArtifactCache
Sourcepub fn new(config: ArtifactCacheConfig) -> Self
pub fn new(config: ArtifactCacheConfig) -> Self
Create a new artifact cache with the given configuration.
Sourcepub fn default_config() -> Self
pub fn default_config() -> Self
Create a cache with default configuration.
Sourcepub fn memory_pressure_snapshot(
&self,
now_nanos: u64,
) -> ArtifactMemoryPressureSnapshot
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.
Sourcepub const fn statistics(&self) -> &CacheStatistics
pub const fn statistics(&self) -> &CacheStatistics
Get current cache statistics.
Sourcepub const fn config(&self) -> &ArtifactCacheConfig
pub const fn config(&self) -> &ArtifactCacheConfig
Get current cache configuration.
Sourcepub const fn current_size_bytes(&self) -> u64
pub const fn current_size_bytes(&self) -> u64
Get the current total size of cached artifacts.
Sourcepub fn get(&mut self, id: &str, now_nanos: u64) -> Option<&[u8]>
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.
Sourcepub fn put(&mut self, id: String, data: Vec<u8>, now_nanos: u64) -> bool
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.
Sourcepub fn remove(&mut self, id: &str) -> bool
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.
Sourcepub fn evict(&mut self, target_bytes: u64) -> u32
pub fn evict(&mut self, target_bytes: u64) -> u32
Evict artifacts based on the configured eviction policy. Returns the number of artifacts evicted.
Sourcepub fn invalidate_expired(&mut self, now_nanos: u64) -> u32
pub fn invalidate_expired(&mut self, now_nanos: u64) -> u32
Remove all expired artifacts from the cache. Returns the number of artifacts invalidated.