Sycophant.Auth.GithubCopilot.TokenCache (sycophant v0.4.2)

Copy Markdown

Supervised GenServer that caches Copilot tokens per {github_host, sha256(gh_token)}.

  • Lazily refreshes on fetch/2 when within 30s of expires_at.
  • Serializes concurrent refreshes per cache key (no thundering herd).
  • 32-entry LRU keeps memory bounded.
  • State has a custom Inspect impl that redacts copilot_token.

Public API: fetch/2. All other functions are GenServer internals.

Summary

Functions

Returns a specification to start this module under a supervisor.

Returns a valid Copilot token entry for the given GitHub credential.

Starts the token cache. Called by Sycophant.Application.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

fetch(github_host, github_token)

@spec fetch(String.t(), String.t()) ::
  {:ok, Sycophant.Auth.GithubCopilot.TokenCache.Entry.t()}
  | {:error, Splode.Error.t()}

Returns a valid Copilot token entry for the given GitHub credential.

Blocks until either a cached entry is available or a fresh exchange completes.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the token cache. Called by Sycophant.Application.