CliDeps.Cache (CliDeps v0.1.0)

Copy Markdown View Source

Caches check results with a time-to-live.

A tool being installed does not change between requests, but it does change between deploys, so results expire rather than persisting forever. The default is one hour.

Entries live in :persistent_term, which is optimised for data written rarely and read constantly — exactly this shape. The trade-off is that writes are expensive and trigger a global GC scan, so nothing here writes on a cache hit, and the number of keys is bounded by the number of declared tools rather than by traffic.

Summary

Types

Milliseconds an entry stays fresh.

Functions

The default time-to-live in milliseconds.

Fetches a cached value, or computes and stores it.

Drops one tool's cached result, or all of them when given :all.

Reads a cached value if it is present and still fresh.

Stores a value, returning it unchanged so it can be used inline.

Types

ttl()

@type ttl() :: pos_integer() | :infinity

Milliseconds an entry stays fresh.

Functions

default_ttl()

@spec default_ttl() :: pos_integer()

The default time-to-live in milliseconds.

fetch(key, ttl, fun)

@spec fetch(term(), ttl(), (-> value)) :: value when value: term()

Fetches a cached value, or computes and stores it.

fun runs only on a miss or an expired entry.

invalidate(key)

@spec invalidate(term() | :all) :: :ok

Drops one tool's cached result, or all of them when given :all.

lookup(key, ttl)

@spec lookup(term(), ttl()) :: {:ok, term()} | :miss

Reads a cached value if it is present and still fresh.

store(key, value)

@spec store(term(), value) :: value when value: term()

Stores a value, returning it unchanged so it can be used inline.