glimit/ets_store

ETS-backed storage backend for rate limiting.

Uses a public ETS table for low-latency, concurrent access without the overhead of OTP actor messages.

Note: individual ETS operations are atomic, but the get-then-set sequence is not — under very high concurrency a small number of extra requests may slip through. This is an acceptable trade-off for simplicity and performance in typical workloads.

Types

Opaque handle to an ETS-backed store.

pub opaque type EtsStore

Values

pub fn get_count(store: EtsStore) -> Int

Return the number of tracked identifiers.

pub fn make_store(store: EtsStore) -> bucket.Store

Create a bucket.Store backed by this ETS table.

Lock and unlock are no-ops since ETS provides per-key atomicity.

pub fn new() -> EtsStore

Create a new ETS-backed store.

pub fn new_with_sweep(
  max_idle_ms max_idle_ms: option.Option(Int),
  sweep_interval_ms sweep_interval_ms: Int,
) -> EtsStore

Create a new ETS-backed store with automatic periodic sweeping.

Full buckets are removed every sweep_interval_ms milliseconds.

max_idle_ms is ignored. A bucket is kept until it has refilled, because removing it earlier would give an idle client a full burst back.

pub fn remove(store: EtsStore, key: String) -> Result(Nil, Nil)

Remove an identifier from the store.

pub fn sweep(
  store store: EtsStore,
  now now: Int,
  max_idle_ms max_idle_ms: option.Option(Int),
) -> Int

Sweep full buckets from the store.

A bucket is removed only once it has refilled, since a new bucket starts full and removing it changes nothing. max_idle_ms is ignored.

✨ Search Document