carbond.limiter.LimiterPolicyState¶
LimiterPolicyState is used by
LimterPolicy to track request history. It may be
shared by multiple LimterPolicy instances if
:js:attribute:`~carbond.limiter.LimterPolicy.sharedState` is true.
Class¶
-
class
carbond.limiter.LimiterPolicyState()¶ - ¶
visit Arguments - req (
express.request) – the currentRequestobject - selector – the selector for the current request
- timestamp – the time at which the request was processed
(
Date.now()ifundefined)
Description Add the current request for selector.- req (
- ¶
visits Arguments - service (
Service) – the rootServiceinstance
Returns the number of visits for this selector Return type IntegerDescription Get the current number of visits saved for selector.- service (
- ¶
purge Arguments - predicate (
IntegerorFunction) – requests that satisfypredicatewill be purged
Description Purge all visits that satisfy predicate. Ifpredicateis anInteger, then it will be assumed to be a timestamp and all visits that happened beforepredicatewill be purged. If it is aFunction, that function should take a single argument and returntrueif satisfied andfalseotherwise. The single argument topurgewill contain the metadata for an individual visit (currently, this is a timestamp, but other metadata may be included in subclasses ofLimiterPolicy).- predicate (
- ¶
Resets the state for all selectors.