Karta.Credentials.Used (Karta v1.0.0)

When a credential was last used, written without a database write for every request.

Karta.Credentials.used/1 touches this table, which maps a credential id to nothing: it is a set of ids, updated in the caller's process. The ids are written in one statement every :interval milliseconds (default 60,000) and when the application stops, so a request does not wait for the database and does not write to it.

flush/1 writes the pending ids now: all of them, or the ones given. A test passes the ids it touched, so a rollback cannot take another test's row with it. A touch that arrives while a flush is taking its snapshot stays for the next flush.

The table holds the ids of credentials that were authenticated, and nothing else, so it is bounded by the credentials table and no request can put anything else in it.

Options: interval and flush (a function of no arguments that writes the pending touches, default flush(:all)).

Summary

Functions

Returns a specification to start this module under a supervisor.

Writes the pending uses now, with their time of writing: all of them, or the ids given.

Records that id was used; returns once it is in the table.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

flush(which \\ :all)

@spec flush(:all | [Ecto.UUID.t()]) :: :ok

Writes the pending uses now, with their time of writing: all of them, or the ids given.

start_link(opts)

touch(id)

@spec touch(Ecto.UUID.t()) :: :ok

Records that id was used; returns once it is in the table.