struct DigestCache {
file: Option<PathBuf>,
inner: Mutex<CacheInner>,
}Expand description
Remembers which digest each model file had when it was last verified, so a file that has not changed since is not read end to end again.
The state a record is keyed on is the file’s size and modification time, both from the stat a verification needs anyway. When either moves, the record no longer covers the file and the full SHA-256 runs again. Bytes replaced without moving either are taken on the recorded digest: that is the trade for a boot without a 3.07 GB read, and every real replacement - a download, a copy, an edit - moves the mtime.
An Err here is never fatal. A record that cannot be read, or a
directory that cannot be written, costs a hash on the next run rather
than a failed one.
Fields§
§file: Option<PathBuf>None disables the cache entirely, which is what a caller with
no machine-local directory of its own to put it in gets.
inner: Mutex<CacheInner>Implementations§
Source§impl DigestCache
impl DigestCache
Sourcefn hit(&self, file: &Path, spec: &ModelSpec) -> bool
fn hit(&self, file: &Path, spec: &ModelSpec) -> bool
Whether this file, at exactly this state, held these bytes when it was last verified. A digest recorded under a different spec is not a hit: re-hashing is what turns that into a mismatch the caller can act on.
Sourcefn record(&self, file: &Path, state: Option<(u64, u64)>, digest: &str)
fn record(&self, file: &Path, state: Option<(u64, u64)>, digest: &str)
Record a digest computed over file while it was in state.
state is the caller’s, taken before the hash: a stat here could
see a write that landed after the read and store the new state
against the old bytes, which the next boot would then skip.