PrfRateLimiter constructor

PrfRateLimiter(
  1. dynamic prefix, {
  2. required int maxTokens,
  3. required Duration refillDuration,
})

Creates a new rate limiter with the specified prefix and configuration.

  • prefix is used to create unique keys for storing rate limiter data.
  • maxTokens defines the maximum number of operations allowed in the time period.
  • refillDuration specifies the time period over which tokens are fully replenished.

Implementation

PrfRateLimiter(
  prefix, {
  required this.maxTokens,
  required this.refillDuration,
})  : _tokenCount = PrfDouble('prf_${prefix}_rate_tokens',
          defaultValue: maxTokens.toDouble()),
      _lastRefill = PrfDateTime('prf_${prefix}_rate_last_refill',
          defaultValue: DateTime.now());