pub struct DiskCache { /* private fields */ }Expand description
Disk persistence helper for one cached catalogue file.
Implementations§
Source§impl DiskCache
impl DiskCache
Sourcepub fn new(cache_file: PathBuf) -> Self
pub fn new(cache_file: PathBuf) -> Self
Bind a cache to a specific catalogue path. Path is created lazily on first write — readers tolerate the parent dir not existing yet.
Sourcepub async fn read_any(&self) -> Result<Option<CachedCatalogue>, CacheError>
pub async fn read_any(&self) -> Result<Option<CachedCatalogue>, CacheError>
Read the cached snapshot regardless of staleness. Returns:
Ok(Some(snap))— file existed AND parsed cleanly.Ok(None)— file missing OR parse failed (latter emits atracing::warnfor ops triage).Err(CacheError::Io)— only for non-NotFoundI/O errors (permission denied, EIO, etc).
Sourcepub async fn read_fresh(
&self,
now_ms: u64,
ttl_ms: u64,
) -> Result<Option<CachedCatalogue>, CacheError>
pub async fn read_fresh( &self, now_ms: u64, ttl_ms: u64, ) -> Result<Option<CachedCatalogue>, CacheError>
Read only when the snapshot is fresh (younger than ttl_ms
relative to now_ms). Stale entries return Ok(None); the
caller normally falls through to a network refresh and a
subsequent Self::write_atomic.
Sourcepub async fn write_atomic(
&self,
snap: &CachedCatalogue,
) -> Result<(), CacheError>
pub async fn write_atomic( &self, snap: &CachedCatalogue, ) -> Result<(), CacheError>
Persist a snapshot. Implementation:
mkdir -pthe parent dir (idempotent).- Write to a sibling
.tmpfile in the same dir sorenamestays on one filesystem (atomic on POSIX). rename(tmp, final)swaps the live snapshot in one step — readers always see either the prior snapshot or the new one, never a half-written file.- On error any partial
.tmpis best-effort removed.
Sourcepub async fn invalidate(&self) -> Result<(), CacheError>
pub async fn invalidate(&self) -> Result<(), CacheError>
Forget the cache. Returns Ok(()) when file missing
(idempotent) — matches the operator-facing “refresh” RPC’s
expected semantics.
Trait Implementations§
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
Mutably borrows from an owned value. Read more