Class: Memcached
Instance Method Summary collapse
-
#del(key) ⇒ Object
Delete key.
-
#flush ⇒ Object
Flush cache.
-
#get(key) ⇒ Object
Get key.
-
#initialize(config = {}) ⇒ Memcached
constructor
Construct a new Memcached cache object.
-
#set(key, data, ttl) ⇒ Object
Set key.
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? = config['cache']['memcached']['options'] else = { 'value_max_bytes' => 4000000 } end o = {} .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 |
#flush ⇒ Object
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 |