Skip to main content

Cache

Struct Cache 

Source
pub struct Cache<Fs: WritableFilesystem> { /* private fields */ }
Expand description

Handle to the cache tree rooted at <workspace_root>/.haz/cache, parameterised over a WritableFilesystem backend.

The bound is WritableFilesystem (not the read-only Filesystem) because all per-operation methods other than lookup mutate the tree. Carrying the stricter bound on the struct, rather than narrowing it per method, keeps the public signatures uniform.

Implementations§

Source§

impl<Fs: WritableFilesystem> Cache<Fs>

Source

pub fn new(fs: Fs, workspace_root: &Path, hash_algo: HashAlgo) -> Self

Construct a Cache handle for the workspace rooted at workspace_root. The cache root is derived as <workspace_root>/.haz/cache via layout::cache_root.

hash_algo is the active hash function for this cache session and is used by lookup to reject entries that were written under a different algorithm (CACHE-016 step 3).

Source

pub fn workspace_root(&self) -> &Path

The absolute path to the workspace root. Restoration (CACHE-019) needs this to map workspace-anchored /foo/bar paths recorded in the manifest into real filesystem paths.

Source

pub fn cache_root(&self) -> &Path

The absolute path to the cache root, <workspace_root>/.haz/cache.

Source

pub fn hash_algo(&self) -> HashAlgo

The hash function this Cache was constructed with.

Source

pub fn fs(&self) -> &Fs

Borrow the underlying filesystem handle. Useful for tests and for callers that need to inspect cache-adjacent paths through the same backend.

Source§

impl<Fs: WritableFilesystem> Cache<Fs>

Source

pub fn clear(&self) -> Result<(), CleanError>

Remove every cache entry under <workspace_root>/.haz/cache, per CACHE-021.

Idempotent on an absent cache root: calling clear when the cache tree does not exist returns Ok(()), not an error. The implementation only touches paths under the cache root; the rest of the workspace is left alone.

§Errors

Returns CleanError::Io wrapping the underlying FsError if the recursive removal fails for any reason other than “the cache root did not exist”.

Source

pub fn clean(&self, opts: &CleanOptions) -> Result<CleanReport, CleanError>

Walk the cache root and reclaim every artefact named by the CleanOptions mode flags per AUX-022..AUX-027.

Eviction priority follows AUX-024 (soft > max_age > max_size); each entry contributes to exactly one per-mode count. Under dry_run, the eviction set is computed and reported but no file or directory is removed.

Idempotent on an absent cache root.

§Errors

Returns CleanError::Io wrapping the underlying FsError if any filesystem operation along the walk fails. Unparseable manifests are NOT an error: those entries surface as the soft-eligible “objectively stale” case.

Source§

impl<Fs: WritableFilesystem> Cache<Fs>

Source

pub fn info(&self) -> Result<CacheInfoReport, CacheInfoError>

Walk the cache root and classify every entry per AUX-019.

Idempotent on an absent cache root: when <workspace_root>/.haz/cache does not exist, returns the default-zero report rather than an error.

§Errors

Returns CacheInfoError::Io wrapping the underlying FsError when any filesystem read fails. Manifest parse failures and schema mismatches are NOT errors: those entries fold into the CacheInfoReport::corrupt_entries count.

Source§

impl<Fs: WritableFilesystem> Cache<Fs>

Source

pub fn lookup(&self, key: &CacheKey) -> Option<Manifest>

Look up the cache entry for key.

Returns Some(Manifest) on a hit (every consistency check from CACHE-016 passed), or None on any miss. Miss reasons enumerated by CACHE-016:

  1. manifest file absent or unreadable;
  2. manifest JSON malformed, contains unknown fields, or uses an unknown hash_function value;
  3. manifest’s chapter_revision does not match crate::CHAPTER_REVISION;
  4. manifest’s hash_function does not match the cache’s active haz_domain::settings::cache::HashAlgo;
  5. any output blob the manifest references is missing, not a regular file, or has a size different from the manifest’s recorded size;
  6. the captured stdout or stderr stream is missing, not a regular file, or has a size different from the manifest’s recorded stdout_len / stderr_len.
Source

pub fn lookup_status( &self, key: &CacheKey, ) -> Result<CacheLookupStatus, CacheLookupError>

Introspecting variant of Self::lookup for AUX-015 step 11.

Performs the same per-entry checks as Self::lookup but discriminates the outcome into the four spec-named sub-states. Reuses the same blob / stream verification (CACHE-015 step 4 / 5), so a hit here is observationally equivalent to a hit from Self::lookup.

§Errors

Returns CacheLookupError::Io wrapping the underlying FsError for filesystem errors that are NOT a “missing entry” shape (those collapse into the CacheLookupStatus::MissNoEntry / CacheLookupStatus::MissCorruptEntry variants).

Source§

impl<Fs: WritableFilesystem> Cache<Fs>

Source

pub fn restore( &self, manifest: &Manifest, ) -> Result<RestoredStreams, RestoreError>

Restore the cache entry described by manifest per CACHE-019.

Materialises every output declared in the manifest at its workspace-absolute path with the recorded mode and returns the captured stdout/stderr bytes. The caller MUST have just obtained manifest from Cache::lookup; the cache trusts the manifest content (paths, content hashes, sizes, modes) as truth and does not re-verify it.

On error, the staging directory under the cache root is removed regardless of which phase failed, so no transient scratch space leaks. If the error occurs after one or more targets have already been renamed onto, those targets remain published; the caller MUST treat the error as a miss and re-run the task fresh (CACHE-020 second paragraph).

§Errors

Returns RestoreError::Io wrapping the underlying FsError if any filesystem operation along the phases fails.

Source§

impl<Fs: WritableFilesystem> Cache<Fs>

Source

pub fn store( &self, key: &CacheKey, inputs: &StoreInputs<'_>, ) -> Result<(), StoreError>

Persist a successful run as a cache entry under key, per CACHE-017.

The caller MUST only invoke this for runs whose process exit status was 0 (CACHE-018); the method does not verify that, but always records exit_status = 0 in the manifest.

The entry is written atomically: a successful return means the final entry directory <shard>/<key>/ is visible with a complete manifest. A returned Err leaves at most a stray tmp directory on the shard, which future clean --soft invocations (CACHE-022) will reclaim.

§Errors

Returns StoreError::Io wrapping the underlying FsError if any filesystem operation along the phases fails.

Trait Implementations§

Source§

impl<Fs: Clone + WritableFilesystem> Clone for Cache<Fs>

Source§

fn clone(&self) -> Cache<Fs>

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<Fs: Debug + WritableFilesystem> Debug for Cache<Fs>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Fs> Freeze for Cache<Fs>
where Fs: Freeze,

§

impl<Fs> RefUnwindSafe for Cache<Fs>
where Fs: RefUnwindSafe,

§

impl<Fs> Send for Cache<Fs>
where Fs: Send,

§

impl<Fs> Sync for Cache<Fs>
where Fs: Sync,

§

impl<Fs> Unpin for Cache<Fs>
where Fs: Unpin,

§

impl<Fs> UnsafeUnpin for Cache<Fs>
where Fs: UnsafeUnpin,

§

impl<Fs> UnwindSafe for Cache<Fs>
where Fs: UnwindSafe,

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

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V