Set :expires_in on throttle cache counters

Should reduce memcached evictions
This commit is contained in:
Aaron Suggs 2012-08-09 10:58:25 -04:00
parent 0656975d98
commit 853c9ceef3
2 changed files with 6 additions and 4 deletions

View file

@ -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

View file

@ -1,5 +1,5 @@
module Rack
module Attack
VERSION = '1.3.0'
VERSION = '1.3.1'
end
end