Class: Cachetastic::Adapters::Dalli
- Defined in:
- lib/cachetastic/adapters/dalli.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#delete(key) ⇒ Object
set.
-
#expire_all ⇒ Object
delete.
-
#get(key) ⇒ Object
:nodoc:.
-
#initialize(klass) ⇒ Dalli
constructor
:nodoc:.
-
#set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry) ⇒ Object
get.
-
#transform_key(key) ⇒ Object
expire_all.
-
#valid? ⇒ Boolean
Return
false
if the connection to Memcached is eithernil
or not active.
Methods inherited from Base
Constructor Details
#initialize(klass) ⇒ Dalli
:nodoc:
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/cachetastic/adapters/dalli.rb', line 5 def initialize(klass) # :nodoc: define_accessor(:dalli_servers) define_accessor(:dalli_options) define_accessor(:dalli_username) define_accessor(:dalli_password) self.dalli_servers = ['127.0.0.1:11211'] self. = {} super connection end |
Instance Method Details
#delete(key) ⇒ Object
set
24 25 26 |
# File 'lib/cachetastic/adapters/dalli.rb', line 24 def delete(key) # :nodoc: connection.delete(transform_key(key)) end |
#expire_all ⇒ Object
delete
28 29 30 31 32 |
# File 'lib/cachetastic/adapters/dalli.rb', line 28 def expire_all # :nodoc: increment_version @_mc_connection = nil return nil end |
#get(key) ⇒ Object
:nodoc:
16 17 18 |
# File 'lib/cachetastic/adapters/dalli.rb', line 16 def get(key) # :nodoc: connection.get(transform_key(key), false) end |
#set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry) ⇒ Object
get
20 21 22 |
# File 'lib/cachetastic/adapters/dalli.rb', line 20 def set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry) # :nodoc: connection.set(transform_key(key), marshal(value), expiry_time, false) end |
#transform_key(key) ⇒ Object
expire_all
34 35 36 |
# File 'lib/cachetastic/adapters/dalli.rb', line 34 def transform_key(key) # :nodoc: key.to_s.hexdigest end |
#valid? ⇒ Boolean
Return false
if the connection to Memcached is either nil
or not active.
40 41 42 43 44 |
# File 'lib/cachetastic/adapters/dalli.rb', line 40 def valid? return false if @_mc_connection.nil? return false unless @_mc_connection.stats return true end |