RateLimiter class
Rate limiter using sliding window algorithm
Constructors
- RateLimiter({required RateLimitConfig config, Logger? logger})
-
Creates a rate limiter enforcing
config; defaults to aLogger('RateLimiter')whenloggeris not supplied.
Properties
- config → RateLimitConfig
-
The policy this limiter enforces.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
checkLimit(
String key) → Future< Duration?> - Check if a request is allowed and return retry time if not
-
clearAll(
) → void - Clear all rate limit data
-
clearKey(
String key) → void - Clear all rate limit data for a key
-
execute<
T> (String key, Future< T> request()) → Future<T> - Execute a request with rate limiting
-
getRemainingRequests(
String key) → int - Get remaining requests in current window
-
getRequestCount(
String key) → int - Get current request count for a key
-
getResetTime(
String key) → Duration? - Get time until rate limit reset
-
getStats(
) → Map< String, dynamic> - Get statistics for monitoring
-
isAllowed(
String key) → Future< bool> - Check if a request is allowed (simple boolean version)
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
recordRequest(
String key) → Future< void> - Record a request
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited