mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-27 15:07:41 +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
|
end
|
||||||
|
|
||||||
def count(unprefixed_key, period)
|
def count(unprefixed_key, period)
|
||||||
key = "#{prefix}:#{Time.now.to_i/period}:#{unprefixed_key}"
|
epoch_time = Time.now.to_i
|
||||||
result = store.increment(key, 1)
|
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
|
# NB: Some stores return nil when incrementing uninitialized values
|
||||||
if result.nil?
|
if result.nil?
|
||||||
store.write(key, 1)
|
store.write(key, 1, :expires_in => expires_in)
|
||||||
end
|
end
|
||||||
result || 1
|
result || 1
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
module Rack
|
module Rack
|
||||||
module Attack
|
module Attack
|
||||||
VERSION = '1.3.0'
|
VERSION = '1.3.1'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue