class Rack::Throttle::Minute
This rate limiter strategy throttles the application by defining a maximum number of allowed HTTP requests per minute (by default, 60 requests per minute, which works out to an average of 1 request per second).
Note that this strategy doesn't use a sliding time window, but rather tracks requests per distinct minute. This means that the throttling counter is reset every minute.
@example Allowing up to 60 requests/minute
use Rack::Throttle::Minute
@example Allowing up to 100 requests per minute
use Rack::Throttle::Minute, :max => 100
Public Class Methods
new(app, options = {})
click to toggle source
@param [#call] app @param [Hash{Symbol => Object}] options @option options [Integer] :max (60)
Calls superclass method
# File lib/rack/throttle/minute.rb, line 23 def initialize(app, options = {}) super end
Public Instance Methods
max_per_minute(request = nil)
click to toggle source
# File lib/rack/throttle/minute.rb, line 28 def max_per_minute(request = nil) @max_per_minute ||= options[:max_per_minute] || options[:max] || 60 end
Also aliased as: max_per_window
Protected Instance Methods
cache_key(request)
click to toggle source
@param [Rack::Request] request @return [String]
Calls superclass method
# File lib/rack/throttle/minute.rb, line 39 def cache_key(request) [super, Time.now.strftime('%Y-%m-%dT%H:%M')].join(':') end