dalli 2.2.1 → 2.3.0

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/Gemfile CHANGED
@@ -3,6 +3,7 @@ source :rubygems
3
3
  gemspec
4
4
 
5
5
  gem 'rake'
6
+ gem 'kgio', :platform => :mri
6
7
 
7
8
  group :test do
8
9
  gem 'simplecov'
data/History.md CHANGED
@@ -1,6 +1,10 @@
1
1
  Dalli Changelog
2
2
  =====================
3
3
 
4
+ 2.3.0
5
+ =======
6
+ - Added the ability to swap out the serializer used to [de]serialize cache data [brianmario, #274]
7
+
4
8
  2.2.1
5
9
  =======
6
10
 
data/README.md CHANGED
@@ -86,8 +86,15 @@ Here's a more comprehensive example that sets a reasonable default for maximum c
86
86
 
87
87
  To use Dalli for Rails session storage that times out after 20 minutes, in `config/initializers/session_store.rb`:
88
88
 
89
+ For Rails >= 3.2.4:
90
+
89
91
  Rails.application.config.session_store ActionDispatch::Session::CacheStore, :expire_after => 20.minutes
90
92
 
93
+ For Rails 3.x:
94
+
95
+ require 'action_dispatch/middleware/session/dalli_store'
96
+ Rails.application.config.session_store :dalli_store, :memcache_server => ['host1', 'host2'], :namespace => 'sessions', :key => '_foundation_session', :expire_after => 20.minutes
97
+
91
98
  Dalli does not support Rails 2.x.
92
99
 
93
100
 
@@ -186,6 +186,14 @@ module ActiveSupport
186
186
  @data.reset
187
187
  end
188
188
 
189
+ def logger
190
+ Dalli.logger
191
+ end
192
+
193
+ def logger=(new_logger)
194
+ Dalli.logger = new_logger
195
+ end
196
+
189
197
  protected
190
198
 
191
199
  # Read an entry from the cache.
@@ -264,10 +272,6 @@ module ActiveSupport
264
272
  logger.debug("Cache #{operation}: #{key}#{options.blank? ? "" : " (#{options.inspect})"}")
265
273
  end
266
274
 
267
- def logger
268
- Dalli.logger
269
- end
270
-
271
275
  end
272
276
  end
273
277
  end
@@ -35,6 +35,17 @@ module Dalli
35
35
  def self.logger=(logger)
36
36
  @logger = logger
37
37
  end
38
+
39
+ # Default serialization to Marshal
40
+ @serializer = Marshal
41
+
42
+ def self.serializer
43
+ @serializer
44
+ end
45
+
46
+ def self.serializer=(serializer)
47
+ @serializer = serializer
48
+ end
38
49
  end
39
50
 
40
51
  if defined?(RAILS_VERSION) && RAILS_VERSION < '3'
@@ -273,7 +273,7 @@ module Dalli
273
273
  # http://www.hjp.at/zettel/m/memcached_flags.rxml
274
274
  # Looks like most clients use bit 0 to indicate native language serialization
275
275
  # and bit 1 to indicate gzip compression.
276
- FLAG_MARSHALLED = 0x1
276
+ FLAG_SERIALIZED = 0x1
277
277
  FLAG_COMPRESSED = 0x2
278
278
 
279
279
  def serialize(key, value, options=nil)
@@ -281,7 +281,7 @@ module Dalli
281
281
  value = unless options && options[:raw]
282
282
  marshalled = true
283
283
  begin
284
- Marshal.dump(value)
284
+ Dalli.serializer.dump(value)
285
285
  rescue => ex
286
286
  # Marshalling can throw several different types of generic Ruby exceptions.
287
287
  # Convert to a specific exception so we can special case it higher up the stack.
@@ -300,13 +300,13 @@ module Dalli
300
300
  raise Dalli::DalliError, "Value too large, memcached can only store #{@options[:value_max_bytes]} bytes per key [key: #{key}, size: #{value.bytesize}]" if value.bytesize > @options[:value_max_bytes]
301
301
  flags = 0
302
302
  flags |= FLAG_COMPRESSED if compressed
303
- flags |= FLAG_MARSHALLED if marshalled
303
+ flags |= FLAG_SERIALIZED if marshalled
304
304
  [value, flags]
305
305
  end
306
306
 
307
307
  def deserialize(value, flags)
308
308
  value = Zlib::Inflate.inflate(value) if (flags & FLAG_COMPRESSED) != 0
309
- value = Marshal.load(value) if (flags & FLAG_MARSHALLED) != 0
309
+ value = Dalli.serializer.load(value) if (flags & FLAG_SERIALIZED) != 0
310
310
  value
311
311
  rescue TypeError, ArgumentError
312
312
  raise DalliError, "Unable to unmarshal value: #{$!.message}"
@@ -1,3 +1,3 @@
1
1
  module Dalli
2
- VERSION = '2.2.1'
2
+ VERSION = '2.3.0'
3
3
  end
@@ -23,7 +23,7 @@ describe 'Encoding' do
23
23
  key = 'foo'
24
24
  assert dc.set(key, 'bar', 1)
25
25
  assert_equal 'bar', dc.get(key)
26
- sleep 2
26
+ sleep 1.2
27
27
  assert_equal nil, dc.get(key)
28
28
  end
29
29
  end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ require 'helper'
3
+ require 'json'
4
+ require 'memcached_mock'
5
+
6
+ describe 'Serializer' do
7
+
8
+ should 'default to Marshal' do
9
+ assert_equal Marshal, Dalli.serializer
10
+ end
11
+
12
+ should 'support a custom serializer' do
13
+ original_serializer = Dalli.serializer
14
+ begin
15
+ Dalli.serializer = JSON
16
+ assert_equal JSON, Dalli.serializer
17
+
18
+ memcached(19127) do |dc|
19
+ assert dc.set("json_test", {"foo" => "bar"})
20
+ assert_equal({"foo" => "bar"}, dc.get("json_test"))
21
+ end
22
+ ensure
23
+ Dalli.serializer = original_serializer
24
+ end
25
+ end
26
+ end
metadata CHANGED
@@ -1,137 +1,130 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: dalli
3
- version: !ruby/object:Gem::Version
4
- version: 2.2.1
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 2.3.0
6
6
  platform: ruby
7
- authors:
8
- - Mike Perham
7
+ authors:
8
+ - Mike Perham
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-05 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: mini_shoulda
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :development
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: mocha
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: rails
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: '3'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '3'
12
+
13
+ date: 2012-10-15 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mini_shoulda
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :development
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: mocha
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :development
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: rails
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: "3"
46
+ type: :development
47
+ version_requirements: *id003
62
48
  description: High performance memcached client for Ruby
63
49
  email: mperham@gmail.com
64
50
  executables: []
51
+
65
52
  extensions: []
53
+
66
54
  extra_rdoc_files: []
67
- files:
68
- - lib/action_dispatch/middleware/session/dalli_store.rb
69
- - lib/active_support/cache/dalli_store.rb
70
- - lib/dalli/client.rb
71
- - lib/dalli/options.rb
72
- - lib/dalli/railtie.rb
73
- - lib/dalli/ring.rb
74
- - lib/dalli/server.rb
75
- - lib/dalli/socket.rb
76
- - lib/dalli/version.rb
77
- - lib/dalli.rb
78
- - lib/rack/session/dalli.rb
79
- - LICENSE
80
- - README.md
81
- - History.md
82
- - Rakefile
83
- - Gemfile
84
- - dalli.gemspec
85
- - Performance.md
86
- - test/abstract_unit.rb
87
- - test/benchmark_test.rb
88
- - test/helper.rb
89
- - test/memcached_mock.rb
90
- - test/test_active_support.rb
91
- - test/test_dalli.rb
92
- - test/test_encoding.rb
93
- - test/test_failover.rb
94
- - test/test_network.rb
95
- - test/test_rack_session.rb
96
- - test/test_ring.rb
97
- - test/test_sasl.rb
98
- - test/test_session_store.rb
55
+
56
+ files:
57
+ - lib/dalli.rb
58
+ - lib/action_dispatch/middleware/session/dalli_store.rb
59
+ - lib/active_support/cache/dalli_store.rb
60
+ - lib/dalli/client.rb
61
+ - lib/dalli/options.rb
62
+ - lib/dalli/railtie.rb
63
+ - lib/dalli/ring.rb
64
+ - lib/dalli/server.rb
65
+ - lib/dalli/socket.rb
66
+ - lib/dalli/version.rb
67
+ - lib/rack/session/dalli.rb
68
+ - LICENSE
69
+ - README.md
70
+ - History.md
71
+ - Rakefile
72
+ - Gemfile
73
+ - dalli.gemspec
74
+ - Performance.md
75
+ - test/abstract_unit.rb
76
+ - test/benchmark_test.rb
77
+ - test/helper.rb
78
+ - test/memcached_mock.rb
79
+ - test/test_active_support.rb
80
+ - test/test_dalli.rb
81
+ - test/test_encoding.rb
82
+ - test/test_failover.rb
83
+ - test/test_network.rb
84
+ - test/test_rack_session.rb
85
+ - test/test_ring.rb
86
+ - test/test_sasl.rb
87
+ - test/test_serializer.rb
88
+ - test/test_session_store.rb
99
89
  homepage: http://github.com/mperham/dalli
100
90
  licenses: []
91
+
101
92
  post_install_message:
102
- rdoc_options:
103
- - --charset=UTF-8
104
- require_paths:
105
- - lib
106
- required_ruby_version: !ruby/object:Gem::Requirement
93
+ rdoc_options:
94
+ - --charset=UTF-8
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
107
98
  none: false
108
- requirements:
109
- - - ! '>='
110
- - !ruby/object:Gem::Version
111
- version: '0'
112
- required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
104
  none: false
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: "0"
118
109
  requirements: []
110
+
119
111
  rubyforge_project:
120
- rubygems_version: 1.8.24
112
+ rubygems_version: 1.8.15
121
113
  signing_key:
122
114
  specification_version: 3
123
115
  summary: High performance memcached client for Ruby
124
- test_files:
125
- - test/abstract_unit.rb
126
- - test/benchmark_test.rb
127
- - test/helper.rb
128
- - test/memcached_mock.rb
129
- - test/test_active_support.rb
130
- - test/test_dalli.rb
131
- - test/test_encoding.rb
132
- - test/test_failover.rb
133
- - test/test_network.rb
134
- - test/test_rack_session.rb
135
- - test/test_ring.rb
136
- - test/test_sasl.rb
137
- - test/test_session_store.rb
116
+ test_files:
117
+ - test/abstract_unit.rb
118
+ - test/benchmark_test.rb
119
+ - test/helper.rb
120
+ - test/memcached_mock.rb
121
+ - test/test_active_support.rb
122
+ - test/test_dalli.rb
123
+ - test/test_encoding.rb
124
+ - test/test_failover.rb
125
+ - test/test_network.rb
126
+ - test/test_rack_session.rb
127
+ - test/test_ring.rb
128
+ - test/test_sasl.rb
129
+ - test/test_serializer.rb
130
+ - test/test_session_store.rb