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 current Request object
  • selector – the selector for the current request
  • timestamp – the time at which the request was processed (Date.now() if undefined)
Description Add the current request for selector.
visits  
Arguments
  • service (Service) – the root Service instance
Returns the number of visits for this selector
Return type Integer
Description Get the current number of visits saved for selector.
purge  
Arguments
  • predicate (Integer or Function) – requests that satisfy predicate will be purged
Description Purge all visits that satisfy predicate. If predicate is an Integer, then it will be assumed to be a timestamp and all visits that happened before predicate will be purged. If it is a Function, that function should take a single argument and return true if satisfied and false otherwise. The single argument to purge will contain the metadata for an individual visit (currently, this is a timestamp, but other metadata may be included in subclasses of LimiterPolicy).

Resets the state for all selectors.

Example