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 returnsnow
. - is found - the function checks if the new TAT (
new_tat == tat + inc
) is less than or equal tomax_tat
. If so, the value associated with the given key is updated: TAT is set tonew_tat
and TTL is set tonew_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
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 returnsnow
. - is found - the function checks if the new TAT (
new_tat == tat + inc
) is less than or equal tomax_tat
. If so, the value associated with the given key is updated: TAT is set tonew_tat
and TTL is set tonew_tat - now
. Otherwise, the value stays untouched. It returns the TAT value read from the storage.
The function must perform the above operations atomically.