Class: Cachetastic::Adapters::Memcached

Inherits:
Base
  • Object
show all
Defined in:
lib/cachetastic/adapters/memcached.rb

Instance Attribute Summary

Attributes inherited from Base

#klass

Instance Method Summary collapse

Methods inherited from Base

#debug?, #marshal, #unmarshal

Constructor Details

#initialize(klass) ⇒ Memcached

Returns a new instance of Memcached.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cachetastic/adapters/memcached.rb', line 5

def initialize(klass)
  # puts "initialize: #{klass}"
  define_accessor(:servers)
  define_accessor(:mc_options)
  define_accessor(:delete_delay)
  self.delete_delay = 0
  self.servers = ['127.0.0.1:11211']
  self.mc_options = {:c_threshold => 10_000,
                     :compression => true,
                     :debug => false,
                     :readonly => false,
                     :urlencode => false}
  super
  connection
end

Instance Method Details

#delete(key) ⇒ Object

set



29
30
31
# File 'lib/cachetastic/adapters/memcached.rb', line 29

def delete(key)
  connection.delete(transform_key(key), self.delete_delay)
end

#expire_allObject

delete



33
34
35
36
37
# File 'lib/cachetastic/adapters/memcached.rb', line 33

def expire_all
  increment_version
  @_mc_connection = nil
  return nil
end

#get(key, &block) ⇒ Object



21
22
23
# File 'lib/cachetastic/adapters/memcached.rb', line 21

def get(key, &block)
  connection.get(transform_key(key), false)
end

#set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry) ⇒ Object

get



25
26
27
# File 'lib/cachetastic/adapters/memcached.rb', line 25

def set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry)
  connection.set(transform_key(key), marshal(value), expiry_time, false)
end

#transform_key(key) ⇒ Object

expire_all



39
40
41
# File 'lib/cachetastic/adapters/memcached.rb', line 39

def transform_key(key)
  key.to_s.hexdigest
end

#valid?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
# File 'lib/cachetastic/adapters/memcached.rb', line 43

def valid?
  return false if @_mc_connection.nil?
  return false unless @_mc_connection.active?
  return true
end