Skip to main content

QCacheRateLimiter

@quik/http


@quik/http / QCacheRateLimiter

Class: QCacheRateLimiter

Defined in: http/src/router/QRateLimiter.ts:39

Rate limiter that stores counters in the active IQCache feature.

When a real cache backend is configured (e.g. Redis via @quik/cache), rate limits are shared across all instances automatically. On the first call the cache is probed to detect whether it is functional; if the default no-op cache is active an in-process Map is used as a transparent fallback, preserving the same single-instance behaviour as before.

Implements​

Constructors​

Constructor​

new QCacheRateLimiter(): QCacheRateLimiter

Returns​

QCacheRateLimiter

Methods​

check()​

check(key, max, windowMs): Promise<{ allowed: boolean; remaining: number; resetMs: number; }>

Defined in: http/src/router/QRateLimiter.ts:58

Check whether the given key is allowed to proceed. Increments the counter for the key and returns whether the request is within the limit.

Parameters​

key​

string

Unique client identifier (e.g. IP address).

max​

number

Maximum allowed requests per window.

windowMs​

number

Duration of the rate-limit window in milliseconds.

Returns​

Promise<{ allowed: boolean; remaining: number; resetMs: number; }>

Implementation of​

IQRateLimiter.check


clear()​

clear(): void

Defined in: http/src/router/QRateLimiter.ts:88

Reset all counters (used during testing or on reset).

Returns​

void

Implementation of​

IQRateLimiter.clear