# class RateLimiter

- RateLimiter
- Reference
- Object

##
Defined in:

rate_limiter.cr

##
Constant Summary

DEFAULT_BUCKET_SIZE = `60`

  Default limits

DEFAULT_CLEANUP_INTERVAL = `300`
DEFAULT_REFILL_RATE = `10`

##
Constructors

- .new(bucket_size : Int32 = DEFAULT_BUCKET_SIZE, refill_rate : Float64 = DEFAULT_REFILL_RATE.to_f)

##
Instance Method Summary

- #allow?(key : String, cost : Int32 = 1) : Bool

  Check if request is allowed and consume a token Returns true if allowed, false if rate limited

- #remaining(key : String) : Int32

  Get remaining tokens for a key

- #reset(key : String)

  Reset bucket for a key

- #retry_after(key : String) : Float64

  Get seconds until a token is available

##
Constructor Detail

def self.new(bucket_size : Int32 = DEFAULT_BUCKET_SIZE, refill_rate : Float64 = DEFAULT_REFILL_RATE.to_f) #

##
Instance Method Detail

def allow?(key : String, cost : Int32 = 1) : Bool #

Check if request is allowed and consume a token Returns true if allowed, false if rate limited

def remaining(key : String) : Int32 #

Get remaining tokens for a key

def reset(key : String) #

Reset bucket for a key

def retry_after(key : String) : Float64 #

Get seconds until a token is available