OTP GenServer managing Setu Bearer token lifecycle.
- ETS table for lock-free reads across all processes
- Proactive refresh 60 s before expiry (TTL 300 s)
- Singleflight deduplication of concurrent refresh calls
:telemetryevents on every refresh
Summary
Functions
Returns a specification to start this module under a supervisor.
Clears the cached token for cfg, forcing a re-fetch on the next call.
Returns a valid Bearer token for cfg.
Types
@type fetch_result() :: {:ok, String.t(), non_neg_integer()} | {:error, SetuClient.Error.t()}
@type state() :: %{ in_flight: %{optional(cache_key()) => {Task.t(), [GenServer.from()]}} }
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec invalidate(SetuClient.Config.t()) :: :ok
Clears the cached token for cfg, forcing a re-fetch on the next call.
@spec token(SetuClient.Config.t()) :: {:ok, String.t()} | {:error, SetuClient.Error.t()}
Returns a valid Bearer token for cfg.
Reads from ETS (lock-free). Falls back to a GenServer call only on cache miss.