Permalink
Browse files

Fixed some counting logic in TimeWindow

  • Loading branch information...
bemurphy committed Mar 22, 2010
1 parent 78e8781 commit b101a5ba2ca25774a8ed46ecce3999e78cba4ebf
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/rack/throttle/time_window.rb
@@ -1,10 +1,10 @@
module Rack; module Throttle
class TimeWindow < Limiter
def allowed?(request)
- count = cache_get(key = cache_key(request)).to_i rescue nil
- allowed = !count || (count + 1) < max_per_window
+ count = cache_get(key = cache_key(request)).to_i + 1 rescue 1
+ allowed = count <= max_per_window
begin
- cache_set(key, count + 1)
+ cache_set(key, count)
allowed
rescue => e
allowed = true

0 comments on commit b101a5b

Please sign in to comment.