Class: Cachetastic::Adapters::Memcache
- Inherits:
-
Base
show all
- Defined in:
- lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/memcache.rb
Overview
This adapter uses Memcache as it’s backing. The configuration for this should look something like this:
my_awesome_cache_options:
debug: false
adapter: memcache
marshall_method: none
default_expiry: <%= 24.hours %>
store_options:
c_threshold: 10_000
compression: true
debug: false
readonly: false
urlencode: false
logging:
logger_1:
type: file
file: log/memcached.log
servers:
- 127.0.0.1:11211
Instance Attribute Summary
Attributes inherited from Base
#logger, #name
Instance Method Summary
collapse
Methods inherited from Base
#configuration, configuration, #debug?, #initialize
Instance Method Details
#delete(key, delay = 0) ⇒ Object
31
32
33
|
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/memcache.rb', line 31
def delete(key, delay = 0)
self.conn.delete(key, delay)
end
|
#expire_all ⇒ Object
39
40
41
|
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/memcache.rb', line 39
def expire_all
self.increment_version(self.name)
end
|
#get(key, raw = false) ⇒ Object
35
36
37
|
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/memcache.rb', line 35
def get(key, raw = false)
self.conn.get(key, raw)
end
|
43
44
45
|
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/memcache.rb', line 43
def inspect
self.conn.inspect + " <version: #{self.version}> #{self.conn.stats.inspect}"
end
|
#set(key, value, expiry = 0, raw = false) ⇒ Object
27
28
29
|
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/memcache.rb', line 27
def set(key, value, expiry = 0, raw = false)
self.conn.set(key, value, expiry, raw)
end
|
22
23
24
25
|
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/memcache.rb', line 22
def setup
self.conn = MemCache.new([configuration.servers].flatten, configuration.store_options.to_hash.merge({:namespace => self.namespace}))
self.version = self.get_version(self.name)
end
|
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/memcache.rb', line 57
def stats
super
begin
puts "Memcache stats for all caches:"
memc = self.conn
puts Kernel.pp_to_s(memc.stats)
paths = `sh -c 'echo $PATH'`
paths = paths.split(':')
memcached_tool_found = false
paths.each do |path|
cmd_path = File.expand_path(File.join(path,'memcached_tool'))
if File.exists?(cmd_path)
memcached_tool_found = true
break
end
end
if memcached_tool_found
configuration.memcache_servers.each do |server|
puts `memcached_tool #{server}`
end
end
rescue
end
puts ""
end
|
#valid? ⇒ Boolean
47
48
49
50
51
52
53
54
55
|
# File 'lib/gems/cachetastic-2.1.2/lib/cachetastic/adapters/memcache.rb', line 47
def valid?
begin
return (self.conn.active? && self.version == self.get_version(self.name))
rescue Exception => e
puts e.message
puts e.backtrace.join("\n")
return false
end
end
|