Class: HttpThreshold::Cache

Inherits:
Rack::Attack::Cache
  • Object
show all
Defined in:
lib/http_threshold/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



6
7
8
9
# File 'lib/http_threshold/cache.rb', line 6

def initialize
  self.store = ::Rails.cache if defined?(::Rails.cache)
  @prefix = 'threshold'
end

Instance Attribute Details

#prefixObject

Returns the value of attribute prefix.



4
5
6
# File 'lib/http_threshold/cache.rb', line 4

def prefix
  @prefix
end

Instance Method Details

#read_count(unprefixed_key, period) ⇒ Object



11
12
13
14
# File 'lib/http_threshold/cache.rb', line 11

def read_count(unprefixed_key, period)
  key, _ = key_and_expiry(unprefixed_key, period)
  store.read(key).to_i
end