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

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseProxy

inherited, lookup, proxies

Constructor Details

#initialize(client) ⇒ DalliProxy

Returns a new instance of DalliProxy.



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

def initialize(client)
  super(client)
  stub_with_if_missing
end

Class Method Details

.handle?(store) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rack/attack/store_proxy/dalli_proxy.rb', line 9

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



50
51
52
53
54
55
56
# File 'lib/rack/attack/store_proxy/dalli_proxy.rb', line 50

def delete(key)
  rescuing do
    with do |client|
      client.delete(key)
    end
  end
end

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



42
43
44
45
46
47
48
# File 'lib/rack/attack/store_proxy/dalli_proxy.rb', line 42

def increment(key, amount, options = {})
  rescuing do
    with do |client|
      client.incr(key, amount, options.fetch(:expires_in, 0), amount)
    end
  end
end

#read(key) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/rack/attack/store_proxy/dalli_proxy.rb', line 26

def read(key)
  rescuing do
    with do |client|
      client.get(key)
    end
  end
end

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



34
35
36
37
38
39
40
# File 'lib/rack/attack/store_proxy/dalli_proxy.rb', line 34

def write(key, value, options = {})
  rescuing do
    with do |client|
      client.set(key, value, options.fetch(:expires_in, 0), raw: true)
    end
  end
end