MemoryRateLimitStore class final

Fixed-window counters in this isolate's memory, like Laravel's RateLimiter (hits + reset time per key): O(1) time and two integers per key, whatever the limit.

Implemented types

Constructors

MemoryRateLimitStore({DateTime clock()?, int maxKeys = 100000})
A store keeping at most maxKeys keys; clock is for tests.

Properties

hashCode → int
The hash code for this object.
no setterinherited
maxKeys → int
Keys retained before the least-recently-touched ones are evicted.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
scope → StateScope
Where the counters live: one isolate, the process, or the cluster.
no setteroverride
size → int
The number of keys held.
no setter

Methods

acquireSync(String key, int maxAttempts, Duration decay, int want) → RateLimitGrant
Records up to want hits (fewer when the window is nearly full); used by workers to lease a batch of hits in one coordinator round trip.
attempt(String key, int maxAttempts, Duration decay) → Future<RateLimitResult>
Records an attempt for key when under the limit.
override
attempts(String key, Duration decay) → Future<int>
Attempts counted in the current window.
override
attemptsSync(String key, Duration decay) → int
The attempts of key in the current window.
attemptSync(String key, int maxAttempts, Duration decay, {int cost = 1}) → RateLimitResult
Synchronous variant (used by the coordinator service). cost counts several hits at once; the attempt is all-or-nothing.
availableIn(String key, int maxAttempts, Duration decay) → Future<Duration>
Time until an attempt is possible again (zero when not limited).
override
availableInSync(String key, int maxAttempts, Duration decay) → Duration
The time until key may try again.
clear(String key) → Future<void>
Forgets the attempts of key.
override
flush() → Future<void>
Forgets every attempt.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
releaseSync(String key, int count, int resetAtMs) → int
Gives back count unused leased hits of the window ending at resetAtMs (ignored once that window is over). Returns the hits left in the window.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited