RateCounter
A rate counter that can be used with EdgeRateLimiter or standalone for counting and rate calculations.
Note: Can only be used when processing requests, not during build-time initialization.
Constructor
new RateCounter(name: string)Open a RateCounter instance with the given name.
Parameters
- name: string
The name of the rate counter.
Methods
increment
View sourceincrement(entry: string, delta: number): voidIncrement the given entry by delta.
Parameters
- entry: string
The entry to increment.
- delta: number
The amount to increment the entry by.
Returns
Throws
TypeErrorifdeltais not a non-negative finite number.
lookupCount
View sourcelookupCount(entry: string, duration: 10 | 20 | 30 | 40 | 50 | 60): numberLook up the current count for an entry over a given duration.
Parameters
- entry: string
The entry to look up.
- duration: 10 | 20 | 30 | 40 | 50 | 60
The duration in seconds to look up alongside the entry.
Returns
The count for the given entry and duration.
Throws
TypeErrorifdurationis not 10, 20, 30, 40, 50, or 60.
lookupRate
View sourcelookupRate(entry: string, window: 1 | 10 | 60): numberLook up the current rate for an entry over a given window.
Parameters
- entry: string
The entry to look up.
- window: 1 | 10 | 60
The time window in seconds to look up alongside the entry.
Returns
The rate for the given entry and window.
Throws
TypeErrorifwindowis not 1, 10, or 60.