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 currentRequest
object - 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 rootService
instance
Returns the number of visits for this selector Return type Integer
Description Get the current number of visits saved for selector
.- service (
- ¶
purge Arguments - predicate (
Integer
orFunction
) – requests that satisfypredicate
will be purged
Description Purge all visits that satisfy predicate
. Ifpredicate
is anInteger
, then it will be assumed to be a timestamp and all visits that happened beforepredicate
will be purged. If it is aFunction
, that function should take a single argument and returntrue
if satisfied andfalse
otherwise. The single argument topurge
will 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.