licence_audit/cache_dir

Shared on-disk cache storage for licence_audit.

Each entry is one JSON file named by the SHA-256 hash of its key. A write goes to a unique temporary file in the same directory, which is then renamed over the entry. Readers therefore see the old entry, the new entry, or no entry, but never a partial file. Concurrent commands need no locks: when two writers race on one key, either value is acceptable.

OTP’s Windows rename moves an existing destination aside before it moves the new file into place, so a reader can see no entry for a short time. That is an ordinary cache miss.

Types

pub type Entry {
  Entry(value: String, cached_at: option.Option(Int))
}

Constructors

pub opaque type Error

An on-disk string cache rooted at one directory.

pub opaque type Store

Values

pub fn access_warning(
  error: Error,
  name: String,
) -> option.Option(String)

Describe an access failure as a warning, excluding ordinary cache misses.

pub fn describe_error(error: Error) -> String
pub fn insert(
  store: Store,
  key: String,
  value: String,
) -> Result(Nil, Error)

Publish an immutable cache value.

pub fn insert_at(
  store: Store,
  key: String,
  value: String,
  cached_at: option.Option(Int),
) -> Result(Nil, Error)

Publish a value and optional expiry timestamp atomically.

pub fn lookup(store: Store, key: String) -> Result(String, Error)

Read one cache value.

pub fn lookup_entry(
  store: Store,
  key: String,
) -> Result(Entry, Error)

Read a value and its timestamp from the same entry file.

pub fn open_table(
  cache_path: option.Option(String),
  directory: String,
  name: String,
) -> Result(Store, Error)

Open a string-keyed cache store, returning its deferred warning on failure.

cache_path overrides the store directory. Otherwise the store uses directory below the user cache directory.

pub fn try_with_warning(
  returned: #(Result(value, error), option.Option(String)),
  next: fn(value) -> #(
    Result(output, error),
    option.Option(String),
  ),
) -> #(Result(output, error), option.Option(String))

Stop on an error without losing the warning returned with it.

pub fn with_warning(
  returned: #(value, option.Option(String)),
  next: fn(value) -> #(output, option.Option(String)),
) -> #(output, option.Option(String))

Pass a cache result to its caller, keeping the latest returned warning.

✨ Search Document