diff --git a/lib/rack/attack/cache.rb b/lib/rack/attack/cache.rb index 2bedd1f..46d7ad2 100644 --- a/lib/rack/attack/cache.rb +++ b/lib/rack/attack/cache.rb @@ -9,11 +9,13 @@ module Rack end def count(unprefixed_key, period) - key = "#{prefix}:#{Time.now.to_i/period}:#{unprefixed_key}" - result = store.increment(key, 1) + epoch_time = Time.now.to_i + expires_in = period - (epoch_time % period) + key = "#{prefix}:#{epoch_time/period}:#{unprefixed_key}" + result = store.increment(key, 1, :expires_in => expires_in) # NB: Some stores return nil when incrementing uninitialized values if result.nil? - store.write(key, 1) + store.write(key, 1, :expires_in => expires_in) end result || 1 end diff --git a/lib/rack/attack/version.rb b/lib/rack/attack/version.rb index 91ccab8..d2472cf 100644 --- a/lib/rack/attack/version.rb +++ b/lib/rack/attack/version.rb @@ -1,5 +1,5 @@ module Rack module Attack - VERSION = '1.3.0' + VERSION = '1.3.1' end end