Class implementing a decay-based rate limiter. Limits requests based on a decay function over time.

Implements

Constructors

Properties

Methods

Constructors

  • Creates an instance of the DecayLimiter class with specified configuration. Initializes the decay cache to manage the request scores and sets the half-life and limit properties.

    Parameters

    • capacity: number

      The maximum capacity for the decay cache to store request scores.

    • halfLife: number

      The time period (in milliseconds) over which the scores decay.

    • limit: number

      The maximum score allowed for a request to be considered valid.

    Returns DecayLimiter

Properties

decays: DecayCache<any>
limit: number

Methods

  • Processes a request for a specific key within the rate limiter. The request's score decays over time and is adjusted based on subsequent requests. Checks if the request's score is below the set limit to determine if it's allowed.

    Parameters

    • key: string

      The key for which the request is made.

    Returns boolean

    True if the request is allowed based on its decayed score, otherwise false.

Generated using TypeDoc