Class: Juno::Adapters::MemcachedDalli
- Defined in:
- lib/juno/adapters/memcached_dalli.rb
Overview
Memcached backend (using gem dalli)
Instance Method Summary collapse
- #clear(options = {}) ⇒ Object
- #close ⇒ Object
- #delete(key, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ MemcachedDalli
constructor
Constructor.
- #key?(key, options = {}) ⇒ Boolean
- #load(key, options = {}) ⇒ Object
- #store(key, value, options = {}) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ MemcachedDalli
Constructor
Options:
-
:server - Memcached server (default localhost:11211)
-
Other options passed to Dalli::Client#new
15 16 17 18 |
# File 'lib/juno/adapters/memcached_dalli.rb', line 15 def initialize( = {}) server = .delete(:server) || 'localhost:11211' @cache = ::Dalli::Client.new(server, ) end |
Instance Method Details
#clear(options = {}) ⇒ Object
44 45 46 47 |
# File 'lib/juno/adapters/memcached_dalli.rb', line 44 def clear( = {}) @cache.flush_all self end |
#close ⇒ Object
49 50 51 52 |
# File 'lib/juno/adapters/memcached_dalli.rb', line 49 def close @cache.close nil end |
#delete(key, options = {}) ⇒ Object
38 39 40 41 42 |
# File 'lib/juno/adapters/memcached_dalli.rb', line 38 def delete(key, = {}) value = @cache.get(key) @cache.delete(key) value end |
#key?(key, options = {}) ⇒ Boolean
20 21 22 |
# File 'lib/juno/adapters/memcached_dalli.rb', line 20 def key?(key, = {}) !!@cache.get(key) end |
#load(key, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/juno/adapters/memcached_dalli.rb', line 24 def load(key, = {}) value = @cache.get(key) if value && .include?(:expires) store(key, value, ) else value end end |
#store(key, value, options = {}) ⇒ Object
33 34 35 36 |
# File 'lib/juno/adapters/memcached_dalli.rb', line 33 def store(key, value, = {}) @cache.set(key, value, [:expires]) value end |