Skip to main content
Version: 1.x

SlidingWindowLogAlgorithm

SlidingWindowLogAlgorithm

Sliding-window log algorithm for smoother limits.

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

type

constructor

method
(storage: RateLimitStorage, config: SlidingWindowConfig) => SlidingWindowLogAlgorithm

Create a sliding-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.