Class: Memcached

Inherits:
Object show all
Defined in:
lib/handset_detection/cache/memcached.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Memcached

Construct a new Memcached cache object.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/handset_detection/cache/memcached.rb', line 32

def initialize(config={})
  if config.include?('cache') and config['cache'].include?('memcached') and not config['cache']['memcached']['servers'].blank?
    servers = config['cache']['memcached']['servers']
  else
    servers = ['localhost:11211'] 
  end

  if config.include?('cache') and config['cache'].include?('memcached') and not config['cache']['memcached']['options'].blank?
    options = config['cache']['memcached']['options']
  else
    options = { 'value_max_bytes' => 4000000 }
  end
  o = {}
  options.each { |k, v| o[k.to_sym] = v }
  @cache = Dalli::Client.new(servers, o)
end

Instance Method Details

#del(key) ⇒ Object

Delete key



63
64
65
# File 'lib/handset_detection/cache/memcached.rb', line 63

def del(key)
  @cache.delete key
end

#flushObject

Flush cache



68
69
70
# File 'lib/handset_detection/cache/memcached.rb', line 68

def flush
  @cache.flush
end

#get(key) ⇒ Object

Get key



51
52
53
# File 'lib/handset_detection/cache/memcached.rb', line 51

def get(key)
  @cache.get key
end

#set(key, data, ttl) ⇒ Object

Set key



57
58
59
# File 'lib/handset_detection/cache/memcached.rb', line 57

def set(key, data, ttl)
  @cache.set key, data, ttl
end