InMemoryRateLimiter<User> class
A simple RateLimiter implementation that uses a simple in-memory map to store rate limiting information.
- Inheritance
-
- Object
- RateLimiter<
User> - InMemoryRateLimiter
Constructors
-
InMemoryRateLimiter(int maxPointsPerWindow, Duration windowDuration, FutureOr<
User> getUser(RequestContext, ResponseContext), {String? errorMessage})
Properties
- errorMessage → String
-
The error message to send to a
User
who has exceeded the rate limit during the current window.finalinherited -
getUser
→ FutureOr<
User> Function(RequestContext, ResponseContext) -
A callback used to compute the current user.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- maxPointsPerWindow → int
-
The maximum number of points that may be consumed
within the given windowDuration.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- windowDuration → Duration
-
The amount of time, during which, a user is not allowed to consume
more than maxPointsPerWindow.
finalinherited
Methods
-
getCurrentWindow(
RequestContext req, ResponseContext res, DateTime currentTime) → FutureOr< RateLimitingWindow< User> > -
Computes the current window in which the user is acting.
override
-
getEndpointCost(
RequestContext req, ResponseContext res, RateLimitingWindow< User> window) → FutureOr<int> -
Computes the amount of points that a given request will cost. This amount
is then added to the amount of points that the user has already consumed
in the current
window
.inherited -
handleRequest(
RequestContext req, ResponseContext res) → Future -
A request middleware that returns
true
if the user has not yet exceeded the maxPointsPerWindow.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
rejectRequest(
RequestContext req, ResponseContext res, RateLimitingWindow< User> window, DateTime currentTime) → FutureOr<Object> -
Signals to a user that they have exceeded the rate limit for the
current window, and terminates execution of the current
RequestContext
.inherited -
sendWindowInformation(
RequestContext req, ResponseContext res, RateLimitingWindow< User> window) → FutureOr<void> -
Alerts the user of information pertinent to the current
window
.inherited -
toString(
) → String -
A string representation of this object.
inherited
-
updateCurrentWindow(
RequestContext req, ResponseContext res, RateLimitingWindow< User> window, DateTime currentTime) → FutureOr<void> -
Updates the underlying store with information about the new
window
that the user is operating in.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited