Cache for short-lived bearer tokens (currently APNS JWTs).
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.
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, String.t()} | {:error, term()}), pos_integer() ) :: {:ok, String.t()} | {: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, token} or {:error, reason}.
@spec invalidate(cache_key()) :: :ok
Removes a cached entry. Used when an instance is stopped.