Class: Rack::Attack::StoreProxy::MemCacheProxy

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/rack/attack/store_proxy/mem_cache_proxy.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ MemCacheProxy

Returns a new instance of MemCacheProxy.



9
10
11
12
# File 'lib/rack/attack/store_proxy/mem_cache_proxy.rb', line 9

def initialize(store)
  super(store)
  stub_with_if_missing
end

Class Method Details

.handle?(store) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/rack/attack/store_proxy/mem_cache_proxy.rb', line 5

def self.handle?(store)
  defined?(::MemCache) && store.is_a?(::MemCache)
end

Instance Method Details

#delete(key, options = {}) ⇒ Object



31
32
33
34
35
36
# File 'lib/rack/attack/store_proxy/mem_cache_proxy.rb', line 31

def delete(key, options={})
  with do |client|
    client.delete(key)
  end
rescue MemCache::MemCacheError
end

#increment(key, amount, options = {}) ⇒ Object



26
27
28
29
# File 'lib/rack/attack/store_proxy/mem_cache_proxy.rb', line 26

def increment(key, amount, options={})
  incr(key, amount)
rescue MemCache::MemCacheError
end

#read(key) ⇒ Object



14
15
16
17
18
# File 'lib/rack/attack/store_proxy/mem_cache_proxy.rb', line 14

def read(key)
  # Second argument: reading raw value
  get(key, true)
  rescue MemCache::MemCacheError
end

#write(key, value, options = {}) ⇒ Object



20
21
22
23
24
# File 'lib/rack/attack/store_proxy/mem_cache_proxy.rb', line 20

def write(key, value, options={})
  # Third argument: writing raw value
  set(key, value, options.fetch(:expires_in, 0), true)
rescue MemCache::MemCacheError
end