MobPush.TokenCache (mob_push v0.2.0)

Copy Markdown View Source

ETS-backed token cache for APNs JWT and FCM OAuth2 access tokens.

Tokens are stored with their expiry time. Callers get a cached token when available and unexpired; otherwise the cache fetches a fresh one.

This GenServer is started automatically by the MobPush application. You don't need to interact with it directly.

Summary

Functions

Returns a specification to start this module under a supervisor.

Evict a cached token (useful when a 401 is received).

Fetch a cached token, or call fetch_fn/0 to produce a fresh one.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

evict(key)

@spec evict(key :: term()) :: :ok

Evict a cached token (useful when a 401 is received).

get(key, fetch_fn)

@spec get(
  key :: term(),
  fetch_fn :: (-> {:ok, {String.t(), expires_at :: integer()}}
                  | {:error, term()})
) :: {:ok, String.t()} | {:error, term()}

Fetch a cached token, or call fetch_fn/0 to produce a fresh one.

start_link(opts)