PenaltyBox

Classin edge-rate-limiter@fastly/js-compute 4.0.0since 3.9.0View source

A penalty box that can be used with EdgeRateLimiter or standalone for adding and checking if an entry is in the dataset.

Note: Can only be used when processing requests, not during build-time initialization.

Constructor

new PenaltyBox(name: string)

Open a penalty box identified by the given name.

Parameters

name: string

The name of the penalty box to open.

Methods

add(entry: string, timeToLive: number): void

Add an entry to the penalty box for the duration of the given timeToLive.

Parameters

entry: string

The entry to add.

timeToLive: number

How long in minutes (1–60) the entry should be added into the penalty box. Value is truncated to the nearest minute.

Returns

void

Throws

  • TypeError if timeToLive is not a number between 1 and 60.
has(entry: string): boolean

Check if an entry is in the penalty box.

Parameters

entry: string

The entry to look up.

Returns

boolean

true if the entry is in the penalty box, otherwise false.