Class: Rack::Attack::StoreProxy::DalliProxy

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ DalliProxy

Returns a new instance of DalliProxy.



19
20
21
22
# File 'lib/rack/attack/store_proxy/dalli_proxy.rb', line 19

def initialize(client)
  super(client)
  stub_with_if_missing
end

Class Method Details

.handle?(store) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
# 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

Instance Method Details

#delete(key) ⇒ Object



45
46
47
48
49
50
# 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 = {}) ⇒ Object



38
39
40
41
42
43
# 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) ⇒ Object



24
25
26
27
28
29
# 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 = {}) ⇒ Object



31
32
33
34
35
36
# 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