rack-attack/lib/rack/attack/cache.rb
2012-07-26 17:29:09 -04:00

21 lines
475 B
Ruby

module Rack
module Attack
class Cache
attr_accessor :store
def initialize
@store = ::Rails.cache if defined?(::Rails.cache)
end
def count(key, expires_in)
result = store.increment(1, :expires_in => expires_in)
# NB: Some stores return nil when incrementing uninitialized values
if result.nil?
store.write(key, 1, :expires_in => expires_in)
end
result || 1
end
end
end
end