licence_audit/cache
Read-through cache for package metadata.
Mutable Hex API entries are keyed by name@version and expire after seven
days. Locked licence and reproducible SBOM entries are keyed by an archive
checksum or commit and never expire. Returned storage errors fall back to
the source fetcher and record a deferred warning. Use --no-cache to bypass
the cache.
Types
Opaque cache handle. Holds a store when caching is enabled and available.
pub opaque type Cache
Configures how the cache module behaves for a given run.
pub type Mode {
Enabled(path: option.Option(String))
Disabled
}
Constructors
-
Enabled(path: option.Option(String))Cache enabled;
pathselects the application root whenSome. -
DisabledBypass the cache entirely (no read, no write, no file opened).
Values
pub fn close(cache: Cache) -> option.Option(String)
Return the warning from opening the cache. Operations return their own warnings explicitly; no file remains open between operations.
pub fn fetch_cached_quiet(
cache: Cache,
name: String,
version: String,
fetcher: fn(String) -> Result(hex.PackageMetadata, hex.Error),
) -> #(
Result(hex.PackageMetadata, hex.Error),
option.Option(String),
)
Reporter-free read-through fetch keyed by name@version.
A variant of wrap for callers that have no progress reporter to thread
(e.g. the notices metadata lookup). Consults the cache, falls through to
fetcher on a miss, best-effort writes successful results back, and falls
back to a stale entry when the upstream fetch fails. Storage failures return
an optional warning without replacing the fetch result.
pub fn fetch_immutable(
cache: Cache,
key: String,
fetcher: fn() -> Result(hex.PackageMetadata, error),
) -> #(Result(hex.PackageMetadata, error), option.Option(String))
Fetch immutable package metadata under a content-addressed key.
Unlike normal Hex package metadata, these entries never expire because the key identifies a locked archive checksum or commit. The namespace version invalidates entries produced by the old, incomplete archive decoder.
pub fn mode_for(
no_cache: Bool,
cache_path: option.Option(String),
) -> Mode
pub fn open(mode: Mode) -> Cache
Open a cache according to mode.
Returns no error value. If the cache path cannot be prepared, the returned
Cache bypasses storage and includes a deferred warning accessible via
close.
pub fn wrap(
cache: Cache,
fetcher: fn(String) -> Result(hex.PackageMetadata, hex.Error),
) -> fn(manifest.Package, progress.Reporter) -> #(
Result(hex.PackageMetadata, hex.Error),
progress.Reporter,
)
Build a fetcher that consults the cache before falling through to
fetcher. Emits verbose progress detail events for hits, misses, and
passthrough. Successful upstream fetches are best-effort written back
to the cache; write failures do not cause the audit to fail.
pub fn wrap_locked(
cache: Cache,
fetcher: fn(String, String, String) -> Result(
hex.PackageMetadata,
error,
),
) -> fn(manifest.Package, progress.Reporter) -> #(
Result(hex.PackageMetadata, error),
progress.Reporter,
)
Read locked Hex metadata through the same immutable cache as reproducible SBOMs.