Class: Twigg::Cache::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/twigg-cache/cache/client.rb

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/twigg-cache/cache/client.rb', line 6

def initialize
  options = {
    compress:        true,
    expires_in:      Config.cache.expiry,
    value_max_bytes: Config.cache.value_max_bytes,
    namespace:       Config.cache.namespace,
  }.delete_if { |key, value| value.nil? }

  @client = Dalli::Client.new("#{Config.cache.host}:#{Config.cache.port}",
                              options)
end

Instance Method Details

#get(key) ⇒ Object



18
19
20
21
22
# File 'lib/twigg-cache/cache/client.rb', line 18

def get(key)
  @client.get(key)
rescue Dalli::RingError
  # degrade gracefully
end

#set(key, value) ⇒ Object



24
25
26
27
28
# File 'lib/twigg-cache/cache/client.rb', line 24

def set(key, value)
  @client.set(key, value)
rescue Dalli::RingError
  # degrade gracefully
end