Class: Moneta::Adapters::Memcache
- Inherits:
-
Object
- Object
- Moneta::Adapters::Memcache
- Includes:
- Defaults
- Defined in:
- lib/moneta/adapters/memcache.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(options = {}) ⇒ Memcache
constructor
A new instance of Memcache.
- #key?(key) ⇒ Boolean
- #store(key, value) ⇒ Object
Methods included from Defaults
Constructor Details
#initialize(options = {}) ⇒ Memcache
Returns a new instance of Memcache.
17 18 19 |
# File 'lib/moneta/adapters/memcache.rb', line 17 def initialize( = {}) @cache = ::MemCache.new(.delete(:server), ) 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 |
#clear ⇒ Object
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
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 |