Cache for short-lived, expensively-derived values: APNS JWTs, per-origin VAPID JWTs and resolved VAPID key pairs.
Reads are lock-free via a public ETS table. On a cache miss, refresh is serialized through this GenServer to prevent a thundering-herd of JWT generations. If the GenServer crashes, its supervisor restarts it and the next call regenerates the token — there is no shared mutex that can be left held, so a killed refresher cannot deadlock the cache.
Summary
Functions
Returns a specification to start this module under a supervisor.
Returns a cached token if still fresh, otherwise asks the cache process
to generate a new one via generate_fn and caches it for ttl_ms.
Removes a cached entry. Used when an instance is stopped.
Removes every entry whose key matches an ETS match pattern, e.g.
{:vapid_jwt, :tenant_web, :_} for all of an instance's per-origin VAPID
JWTs. Used when an instance is stopped or reconfigured.
Types
@type cache_key() :: term()
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec get_or_generate( cache_key(), (-> {:ok, term()} | {:error, term()}), pos_integer() ) :: {:ok, term()} | {:error, term()}
Returns a cached token if still fresh, otherwise asks the cache process
to generate a new one via generate_fn and caches it for ttl_ms.
generate_fn must return {:ok, value} or {:error, reason}; only
{:ok, _} results are cached.
@spec invalidate(cache_key()) :: :ok
Removes a cached entry. Used when an instance is stopped.
@spec invalidate_match(tuple()) :: :ok
Removes every entry whose key matches an ETS match pattern, e.g.
{:vapid_jwt, :tenant_web, :_} for all of an instance's per-origin VAPID
JWTs. Used when an instance is stopped or reconfigured.