limiter v0.1.2 Limiter.Storage behaviour

Behaviour for the storage. The storage stores theoretical arrival time (TAT) and time to live (TTL) for each key.

Summary

Callbacks

Reads the TAT and TTL values for the given key. If the key:

  • is not found - the function stores the key and its value which is composed of the new TAT value (now + inc) and the TTL (inc). It returns now.
  • is found - the function checks if the new TAT (new_tat == tat + inc) is less than or equal to max_tat. If so, the value associated with the given key is updated: TAT is set to new_tat and TTL is set to new_tat - now. Otherwise, the value stays untouched. It returns the TAT value read from the storage

Resets the value (TAT and TTL) associated with the given key

Types

increment()
increment() :: non_neg_integer
key()
key() :: Limiter.key
options()
time()
time() :: non_neg_integer

Callbacks

get_and_store(opts, key, now, inc, max_tat)
get_and_store(opts :: options, key :: key, now :: time, inc :: increment, max_tat :: time) :: time

Reads the TAT and TTL values for the given key. If the key:

  • is not found - the function stores the key and its value which is composed of the new TAT value (now + inc) and the TTL (inc). It returns now.
  • is found - the function checks if the new TAT (new_tat == tat + inc) is less than or equal to max_tat. If so, the value associated with the given key is updated: TAT is set to new_tat and TTL is set to new_tat - now. Otherwise, the value stays untouched. It returns the TAT value read from the storage.

The function must perform the above operations atomically.

reset(opts, key)
reset(opts :: options, key :: key) :: :ok

Resets the value (TAT and TTL) associated with the given key.