Method AcquirePermitAsync
AcquirePermitAsync(IShortLivedStore, string, string, int, TimeSpan, TimeProvider, CancellationToken)
Acquires a permit from a fixed window count, unless permitLimit permits were already acquired in the current window. Windows start
at fixed times on the clock (a one-hour window starts at every full hour), so every server that shares the store counts the same window.
Declaration
public static ValueTask<FixedWindowPermit> AcquirePermitAsync(this IShortLivedStore store, string keyPrefix, string key, int permitLimit, TimeSpan window, TimeProvider timeProvider, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| IShortLivedStore | store | The store. |
| string | keyPrefix | The start of the key, which keeps the counts of one limit apart from all others, for example |
| string | key | What the limit applies to, such as an email address. The store is given a hash of it rather than the value itself, so keys are
compared exactly: |
| int | permitLimit | The number of permits that can be acquired in each window. Must be positive. |
| TimeSpan | window | The length of a window. Must be positive. |
| TimeProvider | timeProvider | The clock that windows are measured by, such as the registered TimeProvider. |
| CancellationToken | cancellationToken | A token to cancel the operation. |
Returns
| Type | Description |
|---|---|
| ValueTask<FixedWindowPermit> |
Remarks
Every attempt is counted, including attempts that acquire no permit.