dalli 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of dalli might be problematic. Click here for more details.
- data/History.md +8 -0
- data/Performance.md +10 -0
- data/lib/active_support/cache/dalli_store.rb +1 -2
- data/lib/active_support/cache/dalli_store23.rb +18 -7
- data/lib/dalli.rb +1 -1
- data/lib/dalli/version.rb +1 -1
- data/test/memcached_mock.rb +1 -1
- data/test/test_active_support.rb +1 -1
- metadata +2 -2
data/History.md
CHANGED
data/Performance.md
CHANGED
@@ -23,3 +23,13 @@ Times are from a Unibody MBP 2.4Ghz Core 2 Duo running Snow Leopard.
|
|
23
23
|
multiget:ruby:dalli 0.950000 0.310000 1.260000 ( 1.269679)
|
24
24
|
missing:ruby:dalli 1.650000 0.380000 2.030000 ( 2.054383)
|
25
25
|
mixed:ruby:dalli 3.470000 0.750000 4.220000 ( 4.323265)
|
26
|
+
|
27
|
+
Testing 0.9.4 with ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
|
28
|
+
user system total real
|
29
|
+
set:plain:dalli 1.380000 0.350000 1.730000 ( 1.818374)
|
30
|
+
set:ruby:dalli 1.460000 0.320000 1.780000 ( 1.851925)
|
31
|
+
get:plain:dalli 1.420000 0.350000 1.770000 ( 1.866443)
|
32
|
+
get:ruby:dalli 1.570000 0.380000 1.950000 ( 2.028747)
|
33
|
+
multiget:ruby:dalli 0.870000 0.300000 1.170000 ( 1.295592)
|
34
|
+
missing:ruby:dalli 1.420000 0.370000 1.790000 ( 1.925094)
|
35
|
+
mixed:ruby:dalli 2.800000 0.680000 3.480000 ( 3.820694)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: ascii
|
1
2
|
begin
|
2
3
|
require 'dalli'
|
3
4
|
rescue LoadError => e
|
@@ -81,7 +82,6 @@ module ActiveSupport
|
|
81
82
|
response = instrument(:increment, name, :amount => amount) do
|
82
83
|
@data.incr(escape_key(namespaced_key(name, options)), amount)
|
83
84
|
end
|
84
|
-
response == Response::NOT_FOUND ? nil : response.to_i
|
85
85
|
rescue Dalli::DalliError
|
86
86
|
nil
|
87
87
|
end
|
@@ -95,7 +95,6 @@ module ActiveSupport
|
|
95
95
|
response = instrument(:decrement, name, :amount => amount) do
|
96
96
|
@data.decr(escape_key(namespaced_key(name, options)), amount)
|
97
97
|
end
|
98
|
-
response == Response::NOT_FOUND ? nil : response.to_i
|
99
98
|
rescue Dalli::DalliError
|
100
99
|
nil
|
101
100
|
end
|
@@ -22,12 +22,11 @@ module ActiveSupport
|
|
22
22
|
DELETED = "DELETED\r\n"
|
23
23
|
end
|
24
24
|
|
25
|
-
ESCAPE_KEY_CHARS = /[\x00-\x20%\x7F-\xFF]/
|
26
|
-
|
27
25
|
def self.build_mem_cache(*addresses)
|
28
26
|
addresses = addresses.flatten
|
29
27
|
options = addresses.extract_options!
|
30
28
|
addresses = ["localhost"] if addresses.empty?
|
29
|
+
# No need to marshal since we marshal here.
|
31
30
|
Dalli::Client.new(addresses, options)
|
32
31
|
end
|
33
32
|
|
@@ -41,10 +40,14 @@ module ActiveSupport
|
|
41
40
|
# localhost port 11211 (the default memcached port).
|
42
41
|
#
|
43
42
|
def initialize(*addresses)
|
43
|
+
addresses = addresses.flatten
|
44
|
+
options = addresses.extract_options!
|
44
45
|
if addresses.first.respond_to?(:get)
|
45
46
|
@data = addresses.first
|
46
47
|
else
|
47
|
-
|
48
|
+
mem_cache_options = options.dup
|
49
|
+
@namespace = mem_cache_options.delete(:namespace)
|
50
|
+
@data = self.class.build_mem_cache(*(addresses + [mem_cache_options]))
|
48
51
|
end
|
49
52
|
|
50
53
|
extend Strategy::LocalCache
|
@@ -130,8 +133,6 @@ module ActiveSupport
|
|
130
133
|
def write(key, value, options = nil)
|
131
134
|
super
|
132
135
|
method = options && options[:unless_exist] ? :add : :set
|
133
|
-
# memcache-client will break the connection if you send it an integer
|
134
|
-
# in raw mode, so we convert it to a string to be sure it continues working.
|
135
136
|
value = Marshal.dump value
|
136
137
|
@data.send(method, escape_key(key), value, expires_in(options))
|
137
138
|
rescue Dalli::DalliError => e
|
@@ -162,9 +163,19 @@ module ActiveSupport
|
|
162
163
|
end
|
163
164
|
|
164
165
|
private
|
166
|
+
|
167
|
+
# Exists in 2.3.8 but not in 2.3.2 so roll our own version
|
168
|
+
def expires_in(options)
|
169
|
+
expires_in = options && options[:expires_in]
|
170
|
+
|
171
|
+
raise ":expires_in must be a number" if expires_in && !expires_in.is_a?(Numeric)
|
172
|
+
|
173
|
+
expires_in || 0
|
174
|
+
end
|
175
|
+
|
165
176
|
def escape_key(key)
|
166
|
-
|
167
|
-
key = "#{
|
177
|
+
prefix = @namespace.is_a?(Proc) ? @namespace.call : @namespace
|
178
|
+
key = "#{prefix}:#{key}" if prefix
|
168
179
|
key
|
169
180
|
end
|
170
181
|
end
|
data/lib/dalli.rb
CHANGED
data/lib/dalli/version.rb
CHANGED
data/test/memcached_mock.rb
CHANGED
data/test/test_active_support.rb
CHANGED
@@ -95,7 +95,7 @@ class TestActiveSupport < Test::Unit::TestCase
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def connect
|
98
|
-
@dalli = ActiveSupport::Cache.lookup_store(:dalli_store, 'localhost:19122', :expires_in => 10.seconds)
|
98
|
+
@dalli = ActiveSupport::Cache.lookup_store(:dalli_store, 'localhost:19122', :expires_in => 10.seconds, :namespace => 'x')
|
99
99
|
@mc = ActiveSupport::Cache.lookup_store(:mem_cache_store, 'localhost:19122', :expires_in => 10.seconds, :namespace => 'a')
|
100
100
|
@dalli.clear
|
101
101
|
end
|