Attesto.CodeStore.ETS (Attesto v0.5.0)

Copy Markdown View Source

Single-node ETS implementation of Attesto.CodeStore.

Codes live in a public ETS table owned by a GenServer that sweeps expired rows on a fixed interval. take/1 uses :ets.take/2, which fetches and deletes a row in one atomic step, so the single-use guarantee holds against concurrent redemptions on a node. This is a per-node store: a multi-node deployment MUST back Attesto.CodeStore with a shared store (e.g. Postgres DELETE ... RETURNING) so a code issued on one node can be redeemed (once) on another.

Start options

  • :sweep_interval_ms (default 30_000) - how often expired rows are bulk-deleted. Correctness does not depend on sweeping (take/1 returns the row and Attesto.AuthorizationCode re-checks expiry); the sweeper only bounds table size.

Wiring

children = [Attesto.CodeStore.ETS]

then pass the module as the store:

Attesto.AuthorizationCode.issue(Attesto.CodeStore.ETS, attrs)

Summary

Functions

Clear every entry. Test-facing.

Functions

reset()

@spec reset() :: :ok

Clear every entry. Test-facing.

start_link(opts \\ [])

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