MishkaPay.Helpers.TokenCache (Mishka Pay v0.0.1)

Copy Markdown View Source

Access tokens a provider gets for a site's keys (PayPal's OAuth token), kept until shortly before they expire so each call does not ask for a new one. An ETS table read and written by the callers themselves; this process only owns it, so no call ever waits on it.

Two callers that find no token at the same time both ask the provider and both keep theirs: each token is valid, and the next caller reads one of them.

Summary

Functions

Returns a specification to start this module under a supervisor.

Forgets the token under key, such as one the provider no longer takes.

The token kept under key, or a new one from fetch ({:ok, token, expires_in_seconds}), kept for next time. An error from fetch is answered as it is and nothing is kept.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

drop(key)

@spec drop(term()) :: true

Forgets the token under key, such as one the provider no longer takes.

get(key, fetch)

@spec get(term(), (-> {:ok, String.t(), pos_integer()} | {:error, term()})) ::
  {:ok, String.t()} | {:error, term()}

The token kept under key, or a new one from fetch ({:ok, token, expires_in_seconds}), kept for next time. An error from fetch is answered as it is and nothing is kept.