RateLimitLayer class
LAYER 5 — Tracks request frequency per user/IP and blocks excessive requests using a sliding-window counter, backed by a pluggable StorageAdapter.
Defaults to MemoryStorage (single-process, dependency-free). Pass a shared StorageAdapter (e.g. a Redis-backed one) to keep rate-limit state consistent across multiple server instances.
- Implemented types
Constructors
- RateLimitLayer({int maxRequests = 20, Duration window = const Duration(minutes: 1), StorageAdapter? storage})
-
Creates a rate-limit layer, defaulting to MemoryStorage unless a
shared
storageadapter is provided.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- maxRequests → int
-
Maximum number of requests allowed per key within window before
subsequent requests are blocked.
final
- name → String
-
A short, stable, human-readable name used in logs and results.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- storage → StorageAdapter
-
Persistent store of per-key hit timestamps. Defaults to
MemoryStorage; pass a shared adapter for multi-instance
deployments so rate-limit counters aren't reset per instance.
final
- window → Duration
-
The sliding time window over which requests are counted.
final
Methods
-
check(
RequestContext context) → Future< SecurityResult> -
Inspects
contextand returns a SecurityResult.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited