mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
Set :expires_in on throttle cache counters
Should reduce memcached evictions
This commit is contained in:
parent
0656975d98
commit
853c9ceef3
2 changed files with 6 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
module Rack
|
||||
module Attack
|
||||
VERSION = '1.3.0'
|
||||
VERSION = '1.3.1'
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue