Skip to main content
Version: 3.27.2

EdgeRateLimiter.prototype.checkRate

Increment an entry in the rate counter and check if the entry has exceeded some average number of requests per second (RPS) over the given window. If the entry is over the RPS limit for the window, add to the penaltybox for the given timeToLive.

Valid timeToLive is 1 minute to 60 minutes and timeToLive value is truncated to the nearest minute.

Syntax

checkRate(entry, delta, window, limit, timeToLive)

Parameters

  • entry : string
    • The name of the entry to increment and check
  • delta : number
    • The amount to increment the entry by
  • window : number
    • The time period to check across, has to be either 1 second, 10 seconds, or 60 seconds
  • limit : number
    • The requests-per-second limit
  • timeToLive : number
    • In minutes, how long the entry should be added into the penalty-box
    • Valid timeToLive is 1 minute to 60 minutes and timeToLive value is truncated to the nearest minute.

Return value

Returns true if the entry has exceeded the average RPS for the window, otherwise returns false.

Exceptions

  • TypeError
    • Thrown if the provided name value can not be coerced into a string
    • Thrown if the provided delta value is not a positive finite number.
    • Thrown if the provided window value is not either, 1, 10, or 60.
    • Thrown if the provided limit value is not a positive finite number.
    • Thrown if the provided timeToLive value is not either, a number between 1 and 60 inclusively.