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 CHANGED
@@ -1,6 +1,14 @@
1
1
  Dalli Changelog
2
2
  =====================
3
3
 
4
+ 0.9.4
5
+ -----
6
+
7
+ - Dalli support now in rack-bug (http://github.com/brynary/rack-bug), give it a try!
8
+ - Namespace support for Rails 2.3 (bpardee)
9
+ - Bug fixes
10
+
11
+
4
12
  0.9.3
5
13
  -----
6
14
 
@@ -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
- @data = self.class.build_mem_cache(*addresses)
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
- key = key.to_s.gsub(ESCAPE_KEY_CHARS){|match| "%#{match.getbyte(0).to_s(16).upcase}"}
167
- key = "#{key[0, 213]}:md5:#{Digest::MD5.hexdigest(key)}" if key.size > 250
177
+ prefix = @namespace.is_a?(Proc) ? @namespace.call : @namespace
178
+ key = "#{prefix}:#{key}" if prefix
168
179
  key
169
180
  end
170
181
  end
@@ -12,7 +12,7 @@ module Dalli
12
12
 
13
13
  def self.logger
14
14
  @logger ||= begin
15
- (defined?(Rails) && Rails.logger) ||
15
+ (defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger) ||
16
16
  (defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER) ||
17
17
  default_logger
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module Dalli
2
- VERSION = '0.9.3'
2
+ VERSION = '0.9.4'
3
3
  end
@@ -69,7 +69,7 @@ module MemcachedMock
69
69
  # puts "Starting: #{cmd}..."
70
70
  pid = IO.popen(cmd).pid
71
71
  begin
72
- sleep 0.3
72
+ sleep 0.5
73
73
  yield Dalli::Client.new(["localhost:#{port}", "127.0.0.1:#{port}"])
74
74
  ensure
75
75
  Process.kill("TERM", pid)
@@ -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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 3
9
- version: 0.9.3
8
+ - 4
9
+ version: 0.9.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mike Perham