Class: Itrigga::Cache::Dalli

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/itrigga/cache/dalli.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDalli

Returns a new instance of Dalli.



20
21
22
# File 'lib/itrigga/cache/dalli.rb', line 20

def initialize
  @cache = nil
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



18
19
20
# File 'lib/itrigga/cache/dalli.rb', line 18

def cache
  @cache
end

#enabledObject

Returns the value of attribute enabled.



18
19
20
# File 'lib/itrigga/cache/dalli.rb', line 18

def enabled
  @enabled
end

Class Method Details

.setup!(opts = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/itrigga/cache/dalli.rb', line 24

def self.setup!(opts = {})
  servers = opts[:servers] || "localhost:11211"
  opts.delete(:servers)
  
  opts[:default_ttl] ||= opts[:timeout] if opts[:timeout] # rename default_ttl to something easier to use
  opts.delete(:timeout)
  instance.enabled = true
  
  puts "Dalli client init with: #{servers.inspect} - #{opts.inspect}"
  instance.cache = ::Dalli::Client.new(servers, opts)   
end

Instance Method Details

#delete(key, opts = {}) ⇒ Object



48
49
50
# File 'lib/itrigga/cache/dalli.rb', line 48

def delete(key, opts = {})
  cache.delete key
end

#get(key, opts = {}) ⇒ Object



36
37
38
# File 'lib/itrigga/cache/dalli.rb', line 36

def get(key, opts = {})
  cache.get key
end

#set(key, value, opts = {}) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/itrigga/cache/dalli.rb', line 40

def set(key, value, opts = {})
  if opts[:timeout]
    cache.set key, value, opts[:timeout]
  else
    cache.set key, value
  end
end