Skip to main content
Version: 1.x

FixedWindowAlgorithm

FixedWindowAlgorithm

Basic fixed-window counter for low-cost rate limits.

Signature
class FixedWindowAlgorithm implements RateLimitAlgorithm {
public readonly type: RateLimitAlgorithmType = 'fixed-window';
constructor(storage: RateLimitStorage, config: FixedWindowConfig)
consume(key: string) => Promise<RateLimitResult>;
reset(key: string) => Promise<void>;
}

type

constructor

method
(storage: RateLimitStorage, config: FixedWindowConfig) => FixedWindowAlgorithm

Create a fixed-window algorithm bound to a storage backend.

consume

method
(key: string) => Promise<RateLimitResult>

Record one attempt and return the current window status for this key.

reset

method
(key: string) => Promise<void>

Reset the stored key state for this limiter.