Skip to main content

PersistentFingerprintCache

Struct PersistentFingerprintCache 

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

Cross-session persistent cache mapping file paths to their fingerprints.

Entries are keyed by path string.

Implementations§

Source§

impl PersistentFingerprintCache

Source

pub fn new(cache_path: PathBuf) -> Self

Create a new, empty cache backed by cache_path.

The file is not read or written until save or load is called.

Source

pub fn load(cache_path: PathBuf) -> Result<Self>

Load a cache from cache_path.

Returns an empty cache (rather than an error) if the file does not exist. Returns Err only on genuine I/O or parse failures.

§Errors

Returns an io::Error if the file exists but cannot be read or parsed.

Source

pub fn save(&self) -> Result<()>

Save the cache to disk atomically (write temp → rename).

§Errors

Returns an io::Error if writing or renaming fails.

Source

pub fn insert(&mut self, entry: CachedEntry)

Insert or update a CachedEntry.

Source

pub fn remove(&mut self, path: &str) -> Option<CachedEntry>

Remove the entry for path, returning it if it existed.

Source

pub fn len(&self) -> usize

Return the number of entries in the cache.

Source

pub fn is_empty(&self) -> bool

Return true if the cache contains no entries.

Source

pub fn get(&self, path: &str) -> Option<&CachedEntry>

Look up a cached entry by file path without freshness checking.

Use get_valid to validate against on-disk state.

Source

pub fn get_valid(&mut self, path: &str) -> Option<&CachedEntry>

Look up a cached entry, validating that the stored BLAKE3 digest still matches the current file.

Reads the actual file to recompute its BLAKE3 hash. Returns None if:

  • The entry is not in the cache.
  • The file does not exist.
  • The digest has changed (file was modified).

Updates the internal hit/miss counters.

Source

pub fn hits(&self) -> u64

Return the number of cache hits since the cache was loaded or last reset.

Source

pub fn misses(&self) -> u64

Return the number of cache misses since the cache was loaded or last reset.

Source

pub fn hit_rate(&self) -> f64

Return the hit rate (0.0 – 1.0). Returns 0.0 if no lookups have been made.

Source

pub fn reset_stats(&mut self)

Reset hit/miss counters.

Source

pub fn evict_missing(&mut self) -> usize

Evict all entries whose source file no longer exists on disk.

Returns the number of entries evicted.

Source

pub fn evict_stale(&mut self) -> usize

Evict all entries that are stale (file modified since caching).

Recomputes BLAKE3 hashes for all cached files. Entries are removed when the digest no longer matches. Returns the number of entries evicted.

Source

pub fn merge_from(&mut self, other: &Self)

Merge entries from other into this cache.

Entries in other overwrite entries with the same path in self.

Source

pub fn iter(&self) -> impl Iterator<Item = (&String, &CachedEntry)>

Return an iterator over all cached entries.

Trait Implementations§

Source§

impl Clone for PersistentFingerprintCache

Source§

fn clone(&self) -> PersistentFingerprintCache

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PersistentFingerprintCache

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.