class RateLimiter

Defined in:

rate_limiter.cr

Constant Summary

DEFAULT_BUCKET_SIZE = 60

Default limits

DEFAULT_CLEANUP_INTERVAL = 300
DEFAULT_REFILL_RATE = 10

Constructors

Instance Method Summary

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