Skip to content

MemoryRateLimitStore

Defined in: packages/rest/src/store.ts:304

Local memory implementation of RateLimitStore.

new MemoryRateLimitStore(): MemoryRateLimitStore

Defined in: packages/rest/src/store.ts:317

Creates an empty instance.

MemoryRateLimitStore

readonly reservesGlobal: true = true

Defined in: packages/rest/src/store.ts:314

Whether reserve also checks options.global atomically. When it does not, the limiter reads the global reset itself first.

RateLimitStore.reservesGlobal

get size(): number

Defined in: packages/rest/src/store.ts:439

Number of buckets held (for diagnostics and leak checks).

number

extendGlobalReset(scope, waitMs): void

Defined in: packages/rest/src/store.ts:433

Atomically extends a global limit to at least waitMs from now, never shortening a longer one. Optional: without it the limiter reads and writes, which a concurrent writer can shorten.

string

number

void

RateLimitStore.extendGlobalReset


getBucket(key): BucketState | undefined

Defined in: packages/rest/src/store.ts:332

Gets the current state for a bucket key.

string

BucketState | undefined

RateLimitStore.getBucket


getBucketHash(route): string | undefined

Defined in: packages/rest/src/store.ts:324

Gets the server bucket hash for a normalized route.

string

string | undefined

RateLimitStore.getBucketHash


getGlobalReset(scope?): number

Defined in: packages/rest/src/store.ts:426

Gets the global reset timestamp (of scope, when the store keeps several).

string = ""

number

RateLimitStore.getGlobalReset


prune(maxAge?): void

Defined in: packages/rest/src/store.ts:415

Removes buckets whose reset is in the past (or older than maxAge ms).

number = 0

void

RateLimitStore.prune


reconcile(key, update): void

Defined in: packages/rest/src/store.ts:378

Atomically merges what a response said into a bucket, so a late or out-of-order response cannot hand back allowance already reserved. Optional: without it the limiter reads, merges and writes.

string

BucketUpdate

void

RateLimitStore.reconcile


release(key, grant, refund): void

Defined in: packages/rest/src/store.ts:383

Gives back what a granted reservation held, when that is certain to be safe: a probe placeholder is cleared (so the next request may probe), and with refund — the request was never sent — the unit is returned to the window it came from, if that window is still current.

string

number

boolean

void

RateLimitStore.release


reserve(key, options?): Reservation

Defined in: packages/rest/src/store.ts:341

Consumes one unit of the bucket’s allowance.

Single-process reservation is trivially atomic: JavaScript will not interleave this method with another caller’s copy of it.

string

ReserveOptions = {}

Reservation

RateLimitStore.reserve


setBucketHash(route, hash): void

Defined in: packages/rest/src/store.ts:327

Associates a route with a server bucket hash.

string

string

void

RateLimitStore.setBucketHash


setGlobalReset(resetAt, scope?): void

Defined in: packages/rest/src/store.ts:429

Sets the global reset timestamp (of scope, when the store keeps several).

number

string = ""

void

RateLimitStore.setGlobalReset


updateBucket(key, state): void

Defined in: packages/rest/src/store.ts:397

Replaces the state for a bucket key.

string

BucketState

void

RateLimitStore.updateBucket