cachetastic 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,10 +10,13 @@ class Cachetastic::Connection
|
|
10
10
|
def get(name)
|
11
11
|
name = name.to_sym
|
12
12
|
conn = self.connections[name]
|
13
|
+
# puts "connection: #{conn}"
|
14
|
+
# puts "connection.valid? #{conn.valid?}" if conn
|
13
15
|
return conn if conn && conn.valid?
|
16
|
+
# puts "we need to set up a new connection for: #{name}"
|
14
17
|
store = Cachetastic::Stores::Base.get_options(name)["store"].camelcase
|
15
18
|
conn = "Cachetastic::Stores::#{store}".constantize.new(name)
|
16
|
-
self.connections[name] = conn
|
19
|
+
self.connections[name.to_sym] = conn
|
17
20
|
return conn
|
18
21
|
end
|
19
22
|
|
data/lib/cachetastic_logger.rb
CHANGED
@@ -5,11 +5,8 @@ class Cachetastic::Logger
|
|
5
5
|
|
6
6
|
def initialize(options, cache_name)
|
7
7
|
self.options = options
|
8
|
-
# puts "self.options = #{self.options.inspect}"
|
9
8
|
self.cache_name = cache_name
|
10
9
|
self.options.each_pair do |n, opts|
|
11
|
-
# puts "opts: #{opts.inspect}"
|
12
|
-
# puts "asdfasfsadfaf opts[\"level\"] = #{opts["level"]}"
|
13
10
|
opts["level"] = (opts["level"] ||= "info").to_sym
|
14
11
|
end
|
15
12
|
end
|
@@ -18,7 +15,6 @@ class Cachetastic::Logger
|
|
18
15
|
|
19
16
|
LOG_LEVELS.each do |level|
|
20
17
|
define_method(level) do |*args|
|
21
|
-
# puts "logging for: #{level}"
|
22
18
|
lm = "[CACHE] [#{level.to_s.upcase}]\t#{Time.now.strftime("%m/%d/%y %H:%m:%S")}"
|
23
19
|
exs = []
|
24
20
|
args.each do |arg|
|
@@ -32,10 +28,6 @@ class Cachetastic::Logger
|
|
32
28
|
lm << "\n#{ex.message}\n" << ex.backtrace.join("\n")
|
33
29
|
end
|
34
30
|
self.options.each_pair do |n, opts|
|
35
|
-
# puts "opts[\"level\"]: #{opts["level"]}"
|
36
|
-
# # if level == opts["level"]
|
37
|
-
# puts "LOG_LEVELS.index(opts[\"level\"]): #{LOG_LEVELS.index(opts["level"])} (#{opts["level"]})"
|
38
|
-
# puts "LOG_LEVELS.index(level): #{LOG_LEVELS.index(level)} (#{level})"
|
39
31
|
if LOG_LEVELS.index(opts["level"]) >= LOG_LEVELS.index(level)
|
40
32
|
case opts["type"]
|
41
33
|
when "file"
|
@@ -32,8 +32,10 @@ class Cachetastic::Stores::Memcache < Cachetastic::Stores::Base
|
|
32
32
|
|
33
33
|
def valid?
|
34
34
|
begin
|
35
|
-
return (self.active? && self.version == self.get_version(self.name))
|
35
|
+
return (self.conn.active? && self.version == self.get_version(self.name))
|
36
36
|
rescue Exception => e
|
37
|
+
puts e.message
|
38
|
+
puts e.backtrace.join("\n")
|
37
39
|
return false
|
38
40
|
end
|
39
41
|
end
|
@@ -64,4 +66,93 @@ class Cachetastic::Stores::Memcache < Cachetastic::Stores::Base
|
|
64
66
|
v
|
65
67
|
end
|
66
68
|
|
67
|
-
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
# class Cachetastic::Stores::Memcache < Cachetastic::Stores::Base
|
73
|
+
#
|
74
|
+
# def setup
|
75
|
+
# self.conn
|
76
|
+
# self.version = self.get_version(self.name)
|
77
|
+
# end
|
78
|
+
#
|
79
|
+
# def set(key, value, expiry = 0)
|
80
|
+
# self.conn.set(key, value, expiry)
|
81
|
+
# end
|
82
|
+
#
|
83
|
+
# def delete(key, delay = 0)
|
84
|
+
# self.conn.delete(key, delay)
|
85
|
+
# end
|
86
|
+
#
|
87
|
+
# def get(key)
|
88
|
+
# self.conn.get(key)
|
89
|
+
# end
|
90
|
+
#
|
91
|
+
# def expire_all
|
92
|
+
# self.increment_version(self.name)
|
93
|
+
# end
|
94
|
+
#
|
95
|
+
# def inspect
|
96
|
+
# self.conn.inspect + " <version: #{self.version}> #{self.conn.stats.inspect}"
|
97
|
+
# end
|
98
|
+
#
|
99
|
+
# def namespace
|
100
|
+
# v = self.get_version(self.name)
|
101
|
+
# return "#{name}.#{v}"
|
102
|
+
# end
|
103
|
+
#
|
104
|
+
# def valid?
|
105
|
+
# begin
|
106
|
+
# return (self.conn.active? && (self.version == self.get_version(self.name)))
|
107
|
+
# rescue Exception => e
|
108
|
+
# puts e.message
|
109
|
+
# puts e.backtrace.join("\n")
|
110
|
+
# return false
|
111
|
+
# end
|
112
|
+
# end
|
113
|
+
#
|
114
|
+
# protected
|
115
|
+
# attr_accessor :version
|
116
|
+
#
|
117
|
+
# def conn
|
118
|
+
# begin
|
119
|
+
# if @conn.nil? || !@conn.active?
|
120
|
+
# @conn = MemCache.new(self.servers, self.store_options.merge({:namespace => self.namespace}))
|
121
|
+
# end
|
122
|
+
# return @conn
|
123
|
+
# rescue Exception => e
|
124
|
+
# @conn.reset
|
125
|
+
# retry
|
126
|
+
# end
|
127
|
+
# end
|
128
|
+
#
|
129
|
+
# def connect_to_ns_versions
|
130
|
+
# begin
|
131
|
+
# ns_versions = MemCache.new(self.servers, self.store_options.merge({:namespace => :namespace_versions}))
|
132
|
+
# yield ns_versions if block_given?
|
133
|
+
# rescue Exception => e
|
134
|
+
# retry
|
135
|
+
# end
|
136
|
+
# end
|
137
|
+
#
|
138
|
+
# def increment_version(name)
|
139
|
+
# name = name.to_s
|
140
|
+
# v = get_version(name)
|
141
|
+
# connect_to_ns_versions do |ns_versions|
|
142
|
+
# ns_versions.set(name, v + 1)
|
143
|
+
# end
|
144
|
+
# end
|
145
|
+
#
|
146
|
+
# def get_version(name)
|
147
|
+
# name = name.to_s
|
148
|
+
# connect_to_ns_versions do |ns_versions|
|
149
|
+
# v = ns_versions.get(name)
|
150
|
+
# if v.nil?
|
151
|
+
# ns_versions.set(name, 1)
|
152
|
+
# v = 1
|
153
|
+
# end
|
154
|
+
# v
|
155
|
+
# end
|
156
|
+
# end
|
157
|
+
#
|
158
|
+
# end
|