Class: Juno::Adapters::MemcachedDalli

Inherits:
Base
  • Object
show all
Defined in:
lib/juno/adapters/memcached_dalli.rb

Overview

Memcached backend (using gem dalli)

Instance Method Summary collapse

Methods inherited from Base

#[], #[]=, #fetch

Constructor Details

#initialize(options = {}) ⇒ MemcachedDalli

Constructor

Options:

  • :server - Memcached server (default localhost:11211)

  • Other options passed to Dalli::Client#new

Parameters:

  • options (Hash) (defaults to: {})


15
16
17
18
# File 'lib/juno/adapters/memcached_dalli.rb', line 15

def initialize(options = {})
  server = options.delete(:server) || 'localhost:11211'
  @cache = ::Dalli::Client.new(server, options)
end

Instance Method Details

#clear(options = {}) ⇒ Object



44
45
46
47
# File 'lib/juno/adapters/memcached_dalli.rb', line 44

def clear(options = {})
  @cache.flush_all
  self
end

#closeObject



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, options = {})
  value = @cache.get(key)
  @cache.delete(key)
  value
end

#key?(key, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/juno/adapters/memcached_dalli.rb', line 20

def key?(key, options = {})
  !!@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, options = {})
  value = @cache.get(key)
  if value && options.include?(:expires)
    store(key, value, options)
  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, options = {})
  @cache.set(key, value, options[:expires])
  value
end