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 and idle buckets are removed every sweep_interval_ms milliseconds. Set max_idle_ms to None to disable idle eviction.

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 and idle buckets from the store.

Search Document