# 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
# File lib/rack/attack/store_proxy/dalli_proxy.rb, line 19 def initialize(client) super(client) stub_with_if_missing end
# File lib/rack/attack/store_proxy/dalli_proxy.rb, line 57 def with; yield __getobj__; end
# 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
# 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
# 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
# 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
# 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