Immutable data structures for efficient rate limiting.
Immutable data structures for efficient rate limiting.
(allow-now? rate-limiter k)
Checks whether the key k
is allowed now or should be rate-limited.
Checks whether the key `k` is allowed now or should be rate-limited.
Protocol for rate limiters that can cache data for missed entries.
Protocol for rate limiters that can cache data for missed entries.
(allow? this k ts)
Checks whether the key k
is allowed at time ts
or should be
rate-limited.
Checks whether the key `k` is allowed at time `ts` or should be rate-limited.
(drop-expired this ts)
Updates the rate limiter such that the state for all keys that are expired
at ts
are removed.
Updates the rate limiter such that the state for all keys that are expired at `ts` are removed.
(get-cached this k)
Gets the cached value for k
, if one exists.
Gets the cached value for `k`, if one exists.
(insert this k ts)
(insert this k ts v)
Updates the rate limiter with key k
at time ts
. If v
is provided, it's
cached if and only if k
is not allowed.
Updates the rate limiter with key `k` at time `ts`. If `v` is provided, it's cached if and only if `k` is not allowed.
(insert-allow? this k ts)
(insert-allow? this k ts v)
Updates the rate limiter with key k
at time ts
. If v
is provided, it's
cached if and only if k
is not allowed.
Returns a triple containing:
k
, if it exists and is dropped by the
insert operation (this happens when the previous insert for k
was
rate-limited and a value was provided for caching).This fn is really just a more convenient/efficient way to run:
[(insert this k ts v)
(allow? this k ts)
(if (allow? this k ts) (get-cached this k))]
Updates the rate limiter with key `k` at time `ts`. If `v` is provided, it's cached if and only if `k` is not allowed. Returns a triple containing: 1. The modified rate limiter. 2. A flag saying if the key should be allowed (true) or rate-limited (false). 3. The previously cached value for `k`, if it exists and is dropped by the insert operation (this happens when the previous insert for `k` was rate-limited and a value was provided for caching). This fn is really just a more convenient/efficient way to run: ``` [(insert this k ts v) (allow? this k ts) (if (allow? this k ts) (get-cached this k))] ```
(take-expired this ts)
Returns a sequence of all cached values that would be expired at ts
, as
key-value pairs.
Returns a sequence of all cached values that would be expired at `ts`, as key-value pairs.
The default config values for new rate limiters.
The default config values for new rate limiters.
(drop-expired-now rate-limiter)
Updates the rate limiter such that the state for all keys that are currently expired are removed.
Updates the rate limiter such that the state for all keys that are currently expired are removed.
(insert! *rl k ts)
(insert! *rl k ts v)
Inserts k
into *rl
at time ts
. If v
is provided, it is cached (if
k
is rate-limited).
Inserts `k` into `*rl` at time `ts`. If `v` is provided, it is cached (if `k` is rate-limited).
(insert-allow?! *rl k ts)
(insert-allow?! *rl k ts v)
Inserts k
into *rl
at time ts
. If v
is provided, it is cached (if k
is rate-limited).
Returns whether the key is allowed or should be rate-limited.
Inserts `k` into `*rl` at time `ts`. If `v` is provided, it is cached (if `k` is rate-limited). Returns whether the key is allowed or should be rate-limited.
(insert-allow?-now rate-limiter k)
(insert-allow?-now rate-limiter k v)
Updates the rate limiter with key k
at the current timestamp. If v
is
provided, it's cached if and only if k
is not allowed.
Returns a triple containing:
k
, if it exists and is dropped by the
insert operation (this happens when the previous insert for k
was
rate-limited and a value was provided for caching).This fn is really just a more convenient/efficient way to run:
(let [allow? (allow-now? this k ts)]
[(insert-now this k ts v) allow? (if allow? (get-cached this k))])
Updates the rate limiter with key `k` at the current timestamp. If `v` is provided, it's cached if and only if `k` is not allowed. Returns a triple containing: 1. The modified rate limiter. 2. A flag saying if the key should be allowed (true) or rate-limited (false). 3. The previously cached value for `k`, if it exists and is dropped by the insert operation (this happens when the previous insert for `k` was rate-limited and a value was provided for caching). This fn is really just a more convenient/efficient way to run: ``` (let [allow? (allow-now? this k ts)] [(insert-now this k ts v) allow? (if allow? (get-cached this k))]) ```
(insert-allow?-now! *rl k)
(insert-allow?-now! *rl k v)
Inserts k
into *rl
at the current timestamp. If v
is provided, it is
cached (if k
is rate-limited).
Returns whether the key is allowed or should be rate-limited.
Inserts `k` into `*rl` at the current timestamp. If `v` is provided, it is cached (if `k` is rate-limited). Returns whether the key is allowed or should be rate-limited.
(insert-now rate-limiter k)
(insert-now rate-limiter k v)
Updates the rate limiter with key k
at time ts
. If v
is provided, it's
cached if and only if k
is not allowed.
Updates the rate limiter with key `k` at time `ts`. If `v` is provided, it's cached if and only if `k` is not allowed.
(insert-now! *rl k)
(insert-now! *rl k v)
Inserts k
into *rl
at the current timestamp. If v
is provided and k
gets rate-limited, v
gets cached.
Inserts `k` into `*rl` at the current timestamp. If `v` is provided and `k` gets rate-limited, `v` gets cached.
(rate-limiter config)
Builds a rate-limiter from the provided configuration.
Builds a rate-limiter from the provided configuration.
(take-expired-now rate-limiter)
Returns a sequence of all cached values that are currently expired, as key-value pairs.
Returns a sequence of all cached values that are currently expired, as key-value pairs.
(truncate! *rl ts)
Removes and returns all keys in *rl
that are expired at time ts
.
Removes and returns all keys in `*rl` that are expired at time `ts`.
(truncate-now! *rl)
Removes all keys in *rl
that are expired at the current time. Returns a
list of key-value pairs
Removes all keys in `*rl` that are expired at the current time. Returns a list of key-value pairs
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close