pub struct DiskCache { /* private fields */ }Expand description
Persistent disk cache for analysis results.
Stores serialized analysis outputs in a directory hierarchy, with per-shard
advisory locking to prevent concurrent writes to the same entry. Supports
atomic writes via NamedTempFile::persist and graceful degradation on I/O errors.
Implementations§
Source§impl DiskCache
impl DiskCache
Sourcepub fn drain_write_failures(&self) -> u64
pub fn drain_write_failures(&self) -> u64
Returns the number of write failures accumulated since the last call and resets the
per-drain counter. The cumulative total_write_failures is never reset.
Sourcepub fn is_degraded(&self) -> bool
pub fn is_degraded(&self) -> bool
Returns true when cumulative write failures have reached DISK_CACHE_DEGRADED_THRESHOLD.
Callers can use this to emit a degraded health signal without polling the counter.
Sourcepub fn cache_stats(&self) -> (u64, u64)
pub fn cache_stats(&self) -> (u64, u64)
Returns cache statistics as (entry_count, total_size_bytes). Note: size_bytes is approximate; deleted files decrement entry_count but not size_bytes.
Source§impl DiskCache
impl DiskCache
Sourcepub fn new(base: PathBuf, disabled: bool) -> Self
pub fn new(base: PathBuf, disabled: bool) -> Self
Creates the cache directory (mode 0700) and returns a new instance.
If disabled is true, or if directory creation fails, all operations are no-ops.
pub fn entry_path(&self, tool: &str, key: &Hash) -> PathBuf
Sourcepub fn get<T: DeserializeOwned>(&self, tool: &str, key: &Hash) -> Option<T>
pub fn get<T: DeserializeOwned>(&self, tool: &str, key: &Hash) -> Option<T>
Retrieves a cached entry by key, decompressing and deserializing on success. Returns None if the entry does not exist, is corrupted, or deserialization fails.
Sourcepub fn put<T: Serialize>(&self, tool: &str, key: &Hash, value: &T)
pub fn put<T: Serialize>(&self, tool: &str, key: &Hash, value: &T)
Atomic write via NamedTempFile::persist (rename(2)). Silently drops all errors.
Sourcepub fn evict_stale(&self, retention_days: u64)
pub fn evict_stale(&self, retention_days: u64)
Removes files not accessed within retention_days. Best-effort; silently drops errors.
Auto Trait Implementations§
impl !Freeze for DiskCache
impl RefUnwindSafe for DiskCache
impl Send for DiskCache
impl Sync for DiskCache
impl Unpin for DiskCache
impl UnsafeUnpin for DiskCache
impl UnwindSafe for DiskCache
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
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