Table of Contents

Class SlidingWindowRateLimiter

Namespace
JD.AI.Core.Security
Assembly
JD.AI.Core.dll

Simple sliding window rate limiter.

public sealed class SlidingWindowRateLimiter : IRateLimiter
Inheritance
SlidingWindowRateLimiter
Implements
Inherited Members

Constructors

SlidingWindowRateLimiter(int, TimeSpan?)

public SlidingWindowRateLimiter(int maxRequests = 60, TimeSpan? window = null)

Parameters

maxRequests int
window TimeSpan?

Methods

AllowAsync(string, CancellationToken)

Returns true if the request is allowed; false if rate-limited.

public Task<bool> AllowAsync(string key, CancellationToken ct = default)

Parameters

key string
ct CancellationToken

Returns

Task<bool>

CheckAsync(string, CancellationToken)

Checks the rate limit and returns detailed result with remaining quota and reset time.

public Task<RateLimitResult> CheckAsync(string key, CancellationToken ct = default)

Parameters

key string
ct CancellationToken

Returns

Task<RateLimitResult>