class Rack::Throttle::TimeWindow

Public Instance Methods

allowed?(request) click to toggle source

Returns `true` if fewer than the maximum number of requests permitted for the current window of time have been made.

@param [Rack::Request] request @return [Boolean]

# File lib/rack/throttle/time_window.rb, line 10
def allowed?(request)
  return true if whitelisted?(request)
  count = cache_get(key = cache_key(request)).to_i + 1 rescue 1
  allowed = count <= max_per_window(request).to_i
  begin
    cache_set(key, count)
    allowed
  rescue => e
    allowed = true
  end
end