Class: Rack::Throttle::PerMinute
- Inherits:
-
TimeWindow
- Object
- Limiter
- TimeWindow
- Rack::Throttle::PerMinute
- Defined in:
- lib/rack/throttle/per_minute.rb
Overview
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 on the minute (according to the server's local timezone).
Instance Attribute Summary
Attributes inherited from Limiter
Instance Method Summary collapse
- #cache_key(request) ⇒ String protected
-
#initialize(app, options = {}) ⇒ PerMinute
constructor
A new instance of PerMinute.
- #max_per_minute ⇒ Object (also: #max_per_window)
Methods inherited from TimeWindow
Methods inherited from Limiter
#allowed?, #blacklisted?, #cache, #cache_get, #cache_has?, #cache_set, #call, #call_on_reject, #client_identifier, #http_error, #http_status, #rate_limit_exceeded, #request_start_time, #whitelisted?
Constructor Details
#initialize(app, options = {}) ⇒ PerMinute
Returns a new instance of PerMinute.
24 25 26 |
# File 'lib/rack/throttle/per_minute.rb', line 24 def initialize(app, = {}) super end |
Instance Method Details
#cache_key(request) ⇒ String (protected)
39 40 41 |
# File 'lib/rack/throttle/per_minute.rb', line 39 def cache_key(request) [super, Time.now.strftime('%Y-%m-%dT%H%M')].join(':') end |
#max_per_minute ⇒ Object Also known as: max_per_window
28 29 30 |
# File 'lib/rack/throttle/per_minute.rb', line 28 def max_per_minute @max_per_minute ||= [:max_per_minute] || [:max] || 60 end |