class Rack::Attack::StoreProxy::MemCacheProxy

Public Class Methods

handle?(store) click to toggle source
# File lib/rack/attack/store_proxy/mem_cache_proxy.rb, line 5
def self.handle?(store)
  defined?(::MemCache) && store.is_a?(::MemCache)
end
new(store) click to toggle source
Calls superclass method
# File lib/rack/attack/store_proxy/mem_cache_proxy.rb, line 9
def initialize(store)
  super(store)
  stub_with_if_missing
end

Private Class Methods

with() { |__getobj__;| ... } click to toggle source
# File lib/rack/attack/store_proxy/mem_cache_proxy.rb, line 43
def with; yield __getobj__; end

Public Instance Methods

delete(key, options={}) click to toggle source
# 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={}) click to toggle source
# 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) click to toggle source
# 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={}) click to toggle source
# 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

Private Instance Methods

stub_with_if_missing() click to toggle source
# File lib/rack/attack/store_proxy/mem_cache_proxy.rb, line 40
def stub_with_if_missing
  unless __getobj__.respond_to?(:with)
    class << self
      def with; yield __getobj__; end
    end
  end
end