Wraith.RateLimit (Wraith v0.1.0)

View Source

A small token bucket in ETS. check(scope, key, limit, per_ms) lets limit hits through per per_ms window for one key (an IP, a visitor id, an email) and answers :ok or {:error, retry_after_ms}. Fixed windows, one row per (scope, key); a sweep every minute drops stale rows.

Scopes and their defaults (limits/0) are what the plugs and LiveViews use; tests may relax them with config :wraith, :rate_limits.

Summary

Functions

Returns a specification to start this module under a supervisor.

Forget a key (tests, or after a successful login).

Functions

check(scope, key)

@spec check(atom(), term()) :: :ok | {:error, non_neg_integer()}

check(scope, key, limit, per_ms)

@spec check(atom(), term(), pos_integer(), pos_integer()) ::
  :ok | {:error, non_neg_integer()}

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

limits()

reset(scope, key)

Forget a key (tests, or after a successful login).

reset_all()

start_link(opts \\ [])