Class: Moneta::Adapters::Memcache

Inherits:
Object
  • Object
show all
Includes:
Defaults
Defined in:
lib/moneta/adapters/memcache.rb

Instance Method Summary collapse

Methods included from Defaults

#[]=, #fetch

Constructor Details

#initialize(options = {}) ⇒ Memcache

Returns a new instance of Memcache.



17
18
19
# File 'lib/moneta/adapters/memcache.rb', line 17

def initialize(options = {})
  @cache = ::MemCache.new(options.delete(:server), options)
end

Instance Method Details

#[](key) ⇒ Object



25
26
27
28
# File 'lib/moneta/adapters/memcache.rb', line 25

def [](key)
  deserialize(@cache.get(key_for(key)))
rescue MemCache::NotFound
end

#clearObject



40
41
42
# File 'lib/moneta/adapters/memcache.rb', line 40

def clear(*)
  @cache.flush
end

#delete(key) ⇒ Object



30
31
32
33
34
# File 'lib/moneta/adapters/memcache.rb', line 30

def delete(key, *)
  value = self[key]
  @cache.delete(key_for(key)) if value
  value
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/moneta/adapters/memcache.rb', line 21

def key?(key, *)
  !self[key].nil?
end

#store(key, value) ⇒ Object



36
37
38
# File 'lib/moneta/adapters/memcache.rb', line 36

def store(key, value, *)
  @cache.set(key_for(key), serialize(value))
end