class Rack::Attack::StoreProxy::DalliProxy

Public Class Methods

handle?(store) click to toggle source
# File lib/rack/attack/store_proxy/dalli_proxy.rb, line 7
def self.handle?(store)
  return false unless defined?(::Dalli)

  # Consider extracting to a separate Connection Pool proxy to reduce
  # code here and handle clients other than Dalli.
  if defined?(::ConnectionPool) && store.is_a?(::ConnectionPool)
    store.with { |conn| conn.is_a?(::Dalli::Client) }
  else
    store.is_a?(::Dalli::Client)
  end
end
new(client) click to toggle source
Calls superclass method
# File lib/rack/attack/store_proxy/dalli_proxy.rb, line 19
def initialize(client)
  super(client)
  stub_with_if_missing
end

Private Class Methods

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

Public Instance Methods

delete(key) click to toggle source
# File lib/rack/attack/store_proxy/dalli_proxy.rb, line 45
def delete(key)
  with do |client|
    client.delete(key)
  end
rescue Dalli::DalliError
end
increment(key, amount, options={}) click to toggle source
# File lib/rack/attack/store_proxy/dalli_proxy.rb, line 38
def increment(key, amount, options={})
  with do |client|
    client.incr(key, amount, options.fetch(:expires_in, 0), amount)
  end
rescue Dalli::DalliError
end
read(key) click to toggle source
# File lib/rack/attack/store_proxy/dalli_proxy.rb, line 24
def read(key)
  with do |client|
    client.get(key)
  end
rescue Dalli::DalliError
end
write(key, value, options={}) click to toggle source
# File lib/rack/attack/store_proxy/dalli_proxy.rb, line 31
def write(key, value, options={})
  with do |client|
    client.set(key, value, options.fetch(:expires_in, 0), raw: true)
  end
rescue Dalli::DalliError
end

Private Instance Methods

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