dalli 2.0.1 → 3.2.8

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.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +671 -0
  3. data/Gemfile +15 -3
  4. data/LICENSE +1 -1
  5. data/README.md +33 -148
  6. data/lib/dalli/cas/client.rb +3 -0
  7. data/lib/dalli/client.rb +293 -131
  8. data/lib/dalli/compressor.rb +40 -0
  9. data/lib/dalli/key_manager.rb +121 -0
  10. data/lib/dalli/options.rb +22 -4
  11. data/lib/dalli/pid_cache.rb +40 -0
  12. data/lib/dalli/pipelined_getter.rb +177 -0
  13. data/lib/dalli/protocol/base.rb +250 -0
  14. data/lib/dalli/protocol/binary/request_formatter.rb +117 -0
  15. data/lib/dalli/protocol/binary/response_header.rb +36 -0
  16. data/lib/dalli/protocol/binary/response_processor.rb +239 -0
  17. data/lib/dalli/protocol/binary/sasl_authentication.rb +60 -0
  18. data/lib/dalli/protocol/binary.rb +173 -0
  19. data/lib/dalli/protocol/connection_manager.rb +255 -0
  20. data/lib/dalli/protocol/meta/key_regularizer.rb +31 -0
  21. data/lib/dalli/protocol/meta/request_formatter.rb +121 -0
  22. data/lib/dalli/protocol/meta/response_processor.rb +211 -0
  23. data/lib/dalli/protocol/meta.rb +178 -0
  24. data/lib/dalli/protocol/response_buffer.rb +54 -0
  25. data/lib/dalli/protocol/server_config_parser.rb +86 -0
  26. data/lib/dalli/protocol/ttl_sanitizer.rb +45 -0
  27. data/lib/dalli/protocol/value_compressor.rb +85 -0
  28. data/lib/dalli/protocol/value_marshaller.rb +59 -0
  29. data/lib/dalli/protocol/value_serializer.rb +91 -0
  30. data/lib/dalli/protocol.rb +19 -0
  31. data/lib/dalli/ring.rb +98 -50
  32. data/lib/dalli/server.rb +4 -524
  33. data/lib/dalli/servers_arg_normalizer.rb +54 -0
  34. data/lib/dalli/socket.rb +154 -53
  35. data/lib/dalli/version.rb +5 -1
  36. data/lib/dalli.rb +49 -13
  37. data/lib/rack/session/dalli.rb +169 -26
  38. metadata +53 -88
  39. data/History.md +0 -262
  40. data/Performance.md +0 -42
  41. data/Rakefile +0 -39
  42. data/dalli.gemspec +0 -28
  43. data/lib/action_dispatch/middleware/session/dalli_store.rb +0 -76
  44. data/lib/active_support/cache/dalli_store.rb +0 -203
  45. data/test/abstract_unit.rb +0 -281
  46. data/test/benchmark_test.rb +0 -187
  47. data/test/helper.rb +0 -41
  48. data/test/memcached_mock.rb +0 -113
  49. data/test/test_active_support.rb +0 -163
  50. data/test/test_dalli.rb +0 -461
  51. data/test/test_encoding.rb +0 -43
  52. data/test/test_failover.rb +0 -107
  53. data/test/test_network.rb +0 -54
  54. data/test/test_ring.rb +0 -85
  55. data/test/test_sasl.rb +0 -83
  56. data/test/test_session_store.rb +0 -224
metadata CHANGED
@@ -1,119 +1,84 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dalli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
5
- prerelease:
4
+ version: 3.2.8
6
5
  platform: ruby
7
6
  authors:
7
+ - Peter M. Goldstein
8
8
  - Mike Perham
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-29 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: mini_shoulda
16
- requirement: &70253543905580 !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: *70253543905580
25
- - !ruby/object:Gem::Dependency
26
- name: mocha
27
- requirement: &70253543905040 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *70253543905040
36
- - !ruby/object:Gem::Dependency
37
- name: rails
38
- requirement: &70253543904560 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ~>
42
- - !ruby/object:Gem::Version
43
- version: '3'
44
- type: :development
45
- prerelease: false
46
- version_requirements: *70253543904560
12
+ date: 2024-02-12 00:00:00.000000000 Z
13
+ dependencies: []
47
14
  description: High performance memcached client for Ruby
48
- email: mperham@gmail.com
15
+ email:
16
+ - peter.m.goldstein@gmail.com
17
+ - mperham@gmail.com
49
18
  executables: []
50
19
  extensions: []
51
20
  extra_rdoc_files: []
52
21
  files:
53
- - lib/action_dispatch/middleware/session/dalli_store.rb
54
- - lib/active_support/cache/dalli_store.rb
22
+ - CHANGELOG.md
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - lib/dalli.rb
27
+ - lib/dalli/cas/client.rb
55
28
  - lib/dalli/client.rb
29
+ - lib/dalli/compressor.rb
30
+ - lib/dalli/key_manager.rb
56
31
  - lib/dalli/options.rb
32
+ - lib/dalli/pid_cache.rb
33
+ - lib/dalli/pipelined_getter.rb
34
+ - lib/dalli/protocol.rb
35
+ - lib/dalli/protocol/base.rb
36
+ - lib/dalli/protocol/binary.rb
37
+ - lib/dalli/protocol/binary/request_formatter.rb
38
+ - lib/dalli/protocol/binary/response_header.rb
39
+ - lib/dalli/protocol/binary/response_processor.rb
40
+ - lib/dalli/protocol/binary/sasl_authentication.rb
41
+ - lib/dalli/protocol/connection_manager.rb
42
+ - lib/dalli/protocol/meta.rb
43
+ - lib/dalli/protocol/meta/key_regularizer.rb
44
+ - lib/dalli/protocol/meta/request_formatter.rb
45
+ - lib/dalli/protocol/meta/response_processor.rb
46
+ - lib/dalli/protocol/response_buffer.rb
47
+ - lib/dalli/protocol/server_config_parser.rb
48
+ - lib/dalli/protocol/ttl_sanitizer.rb
49
+ - lib/dalli/protocol/value_compressor.rb
50
+ - lib/dalli/protocol/value_marshaller.rb
51
+ - lib/dalli/protocol/value_serializer.rb
57
52
  - lib/dalli/ring.rb
58
53
  - lib/dalli/server.rb
54
+ - lib/dalli/servers_arg_normalizer.rb
59
55
  - lib/dalli/socket.rb
60
56
  - lib/dalli/version.rb
61
- - lib/dalli.rb
62
57
  - lib/rack/session/dalli.rb
63
- - LICENSE
64
- - README.md
65
- - History.md
66
- - Rakefile
67
- - Gemfile
68
- - dalli.gemspec
69
- - Performance.md
70
- - test/abstract_unit.rb
71
- - test/benchmark_test.rb
72
- - test/helper.rb
73
- - test/memcached_mock.rb
74
- - test/test_active_support.rb
75
- - test/test_dalli.rb
76
- - test/test_encoding.rb
77
- - test/test_failover.rb
78
- - test/test_network.rb
79
- - test/test_ring.rb
80
- - test/test_sasl.rb
81
- - test/test_session_store.rb
82
- homepage: http://github.com/mperham/dalli
83
- licenses: []
84
- post_install_message:
85
- rdoc_options:
86
- - --charset=UTF-8
58
+ homepage: https://github.com/petergoldstein/dalli
59
+ licenses:
60
+ - MIT
61
+ metadata:
62
+ bug_tracker_uri: https://github.com/petergoldstein/dalli/issues
63
+ changelog_uri: https://github.com/petergoldstein/dalli/blob/main/CHANGELOG.md
64
+ rubygems_mfa_required: 'true'
65
+ post_install_message:
66
+ rdoc_options: []
87
67
  require_paths:
88
68
  - lib
89
69
  required_ruby_version: !ruby/object:Gem::Requirement
90
- none: false
91
70
  requirements:
92
- - - ! '>='
71
+ - - ">="
93
72
  - !ruby/object:Gem::Version
94
- version: '0'
73
+ version: '2.6'
95
74
  required_rubygems_version: !ruby/object:Gem::Requirement
96
- none: false
97
75
  requirements:
98
- - - ! '>='
76
+ - - ">="
99
77
  - !ruby/object:Gem::Version
100
78
  version: '0'
101
79
  requirements: []
102
- rubyforge_project:
103
- rubygems_version: 1.8.15
104
- signing_key:
105
- specification_version: 3
80
+ rubygems_version: 3.5.6
81
+ signing_key:
82
+ specification_version: 4
106
83
  summary: High performance memcached client for Ruby
107
- test_files:
108
- - test/abstract_unit.rb
109
- - test/benchmark_test.rb
110
- - test/helper.rb
111
- - test/memcached_mock.rb
112
- - test/test_active_support.rb
113
- - test/test_dalli.rb
114
- - test/test_encoding.rb
115
- - test/test_failover.rb
116
- - test/test_network.rb
117
- - test/test_ring.rb
118
- - test/test_sasl.rb
119
- - test/test_session_store.rb
84
+ test_files: []
data/History.md DELETED
@@ -1,262 +0,0 @@
1
- Dalli Changelog
2
- =====================
3
-
4
- 2.0.1
5
- =======
6
-
7
- - Fix nil option handling in dalli\_store#write [#188]
8
-
9
- 2.0.0
10
- =======
11
-
12
- - Reimplemented the Rails' dalli\_store to remove use of
13
- ActiveSupport::Cache::Entry which added 109 bytes overhead to every
14
- value stored, was a performance bottleneck and duplicated a lot of
15
- functionality already in Dalli. One benchmark went from 4.0 sec to 3.0
16
- sec with the new dalli\_store. [#173]
17
- - Added reset\_stats operation [#155]
18
- - Added support for configuring keepalive on TCP connections to memcached servers (@bianster, #180)
19
-
20
- Notes:
21
-
22
- * data stored with dalli\_store 2.x is NOT backwards compatible with 1.x.
23
- Upgraders are advised to namespace their keys and roll out the 2.x
24
- upgrade slowly so keys do not clash and caches are warmed.
25
- `config.cache_store = :dalli_store, :expires_in => 24.hours.to_i, :namespace => 'myapp2'`
26
- * data stored with plain Dalli::Client API is unchanged.
27
- * removed support for dalli\_store's race\_condition\_ttl option.
28
- * removed support for em-synchrony and unix socket connection options.
29
- * removed support for Ruby 1.8.6
30
- * removed memcache-client compability layer and upgrade documentation.
31
-
32
-
33
- 1.1.5
34
- =======
35
-
36
- - Coerce input to incr/decr to integer via #to\_i [#165]
37
- - Convert test suite to minitest/spec (crigor, #166)
38
- - Fix encoding issue with keys [#162]
39
- - Fix double namespacing with Rails and dalli\_store. [#160]
40
-
41
- 1.1.4
42
- =======
43
-
44
- - Use 127.0.0.1 instead of localhost as default to avoid IPv6 issues
45
- - Extend DalliStore's :expires\_in when :race\_condition\_ttl is also used.
46
- - Fix :expires\_in option not propogating from DalliStore to Client, GH-136
47
- - Added support for native Rack session store. Until now, Dalli's
48
- session store has required Rails. Now you can use Dalli to store
49
- sessions for any Rack application.
50
-
51
- require 'rack/session/dalli'
52
- use Rack::Session::Dalli, :memcache_server => 'localhost:11211', :compression => true
53
-
54
- 1.1.3
55
- =======
56
-
57
- - Support Rails's autoloading hack for loading sessions with objects
58
- whose classes have not be required yet, GH-129
59
- - Support Unix sockets for connectivity. Shows a 2x performance
60
- increase but keep in mind they only work on localhost. (dfens)
61
-
62
- 1.1.2
63
- =======
64
-
65
- - Fix incompatibility with latest Rack session API when destroying
66
- sessions, thanks @twinge!
67
-
68
- 1.1.1
69
- =======
70
-
71
- v1.1.0 was a bad release. Yanked.
72
-
73
- 1.1.0
74
- =======
75
-
76
- - Remove support for Rails 2.3, add support for Rails 3.1
77
- - Fix socket failure retry logic, now you can restart memcached and Dalli won't complain!
78
- - Add support for fibered operation via em-synchrony (eliaslevy)
79
- - Gracefully handle write timeouts, GH-99
80
- - Only issue bug warning for unexpected StandardErrors, GH-102
81
- - Add travis-ci build support (ryanlecompte)
82
- - Gracefully handle errors in get_multi (michaelfairley)
83
- - Misc fixes from crash2burn, fphilipe, igreg, raggi
84
-
85
- 1.0.5
86
- =======
87
-
88
- - Fix socket failure retry logic, now you can restart memcached and Dalli won't complain!
89
-
90
- 1.0.4
91
- =======
92
-
93
- - Handle non-ASCII key content in dalli_store
94
- - Accept key array for read_multi in dalli_store
95
- - Fix multithreaded race condition in creation of mutex
96
-
97
- 1.0.3
98
- =======
99
-
100
- - Better handling of application marshalling errors
101
- - Work around jruby IO#sysread compatibility issue
102
-
103
-
104
- 1.0.2
105
- =======
106
-
107
- - Allow browser session cookies (blindsey)
108
- - Compatibility fixes (mwynholds)
109
- - Add backwards compatibility module for memcache-client, require 'dalli/memcache-client'. It makes
110
- Dalli more compatible with memcache-client and prints out a warning any time you do something that
111
- is no longer supported so you can fix your code.
112
-
113
- 1.0.1
114
- =======
115
-
116
- - Explicitly handle application marshalling bugs, GH-56
117
- - Add support for username/password as options, to allow multiple bucket access
118
- from the same Ruby process, GH-52
119
- - Add support for >1MB values with :value_max_bytes option, GH-54 (r-stu31)
120
- - Add support for default TTL, :expires_in, in Rails 2.3. (Steven Novotny)
121
- config.cache_store = :dalli_store, 'localhost:11211', {:expires_in => 4.hours}
122
-
123
-
124
- 1.0.0
125
- =======
126
-
127
- Welcome gucki as a Dalli committer!
128
-
129
- - Fix network and namespace issues in get_multi (gucki)
130
- - Better handling of unmarshalling errors (mperham)
131
-
132
- 0.11.2
133
- =======
134
-
135
- - Major reworking of socket error and failover handling (gucki)
136
- - Add basic JRuby support (mperham)
137
-
138
- 0.11.1
139
- ======
140
-
141
- - Minor fixes, doc updates.
142
- - Add optional support for kgio sockets, gives a 10-15% performance boost.
143
-
144
- 0.11.0
145
- ======
146
-
147
- Warning: this release changes how Dalli marshals data. I do not guarantee compatibility until 1.0 but I will increment the minor version every time a release breaks compatibility until 1.0.
148
-
149
- IT IS HIGHLY RECOMMENDED YOU FLUSH YOUR CACHE BEFORE UPGRADING.
150
-
151
- - multi() now works reentrantly.
152
- - Added new Dalli::Client option for default TTLs, :expires_in, defaults to 0 (aka forever).
153
- - Added new Dalli::Client option, :compression, to enable auto-compression of values.
154
- - Refactor how Dalli stores data on the server. Values are now tagged
155
- as "marshalled" or "compressed" so they can be automatically deserialized
156
- without the client having to know how they were stored.
157
-
158
- 0.10.1
159
- ======
160
-
161
- - Prefer server config from environment, fixes Heroku session store issues (thanks JoshMcKin)
162
- - Better handling of non-ASCII values (size -> bytesize)
163
- - Assert that keys are ASCII only
164
-
165
- 0.10.0
166
- ======
167
-
168
- Warning: this release changed how Rails marshals data with Dalli. Unfortunately previous versions double marshalled values. It is possible that data stored with previous versions of Dalli will not work with this version.
169
-
170
- IT IS HIGHLY RECOMMENDED YOU FLUSH YOUR CACHE BEFORE UPGRADING.
171
-
172
- - Rework how the Rails cache store does value marshalling.
173
- - Rework old server version detection to avoid a socket read hang.
174
- - Refactor the Rails 2.3 :dalli\_store to be closer to :mem\_cache\_store.
175
- - Better documentation for session store config (plukevdh)
176
-
177
- 0.9.10
178
- ----
179
-
180
- - Better server retry logic (next2you)
181
- - Rails 3.1 compatibility (gucki)
182
-
183
-
184
- 0.9.9
185
- ----
186
-
187
- - Add support for *_multi operations for add, set, replace and delete. This implements
188
- pipelined network operations; Dalli disables network replies so we're not limited by
189
- latency, allowing for much higher throughput.
190
-
191
- dc = Dalli::Client.new
192
- dc.multi do
193
- dc.set 'a', 1
194
- dc.set 'b', 2
195
- dc.set 'c', 3
196
- dc.delete 'd'
197
- end
198
- - Minor fix to set the continuum sorted by value (kangster)
199
- - Implement session store with Rails 2.3. Update docs.
200
-
201
- 0.9.8
202
- -----
203
-
204
- - Implement namespace support
205
- - Misc fixes
206
-
207
-
208
- 0.9.7
209
- -----
210
-
211
- - Small fix for NewRelic integration.
212
- - Detect and fail on older memcached servers (pre-1.4).
213
-
214
- 0.9.6
215
- -----
216
-
217
- - Patches for Rails 3.0.1 integration.
218
-
219
- 0.9.5
220
- -----
221
-
222
- - Major design change - raw support is back to maximize compatibility with Rails
223
- and the increment/decrement operations. You can now pass :raw => true to most methods
224
- to bypass (un)marshalling.
225
- - Support symbols as keys (ddollar)
226
- - Rails 2.3 bug fixes
227
-
228
-
229
- 0.9.4
230
- -----
231
-
232
- - Dalli support now in rack-bug (http://github.com/brynary/rack-bug), give it a try!
233
- - Namespace support for Rails 2.3 (bpardee)
234
- - Bug fixes
235
-
236
-
237
- 0.9.3
238
- -----
239
-
240
- - Rails 2.3 support (beanieboi)
241
- - Rails SessionStore support
242
- - Passenger integration
243
- - memcache-client upgrade docs, see Upgrade.md
244
-
245
-
246
- 0.9.2
247
- ----
248
-
249
- - Verify proper operation in Heroku.
250
-
251
-
252
- 0.9.1
253
- ----
254
-
255
- - Add fetch and cas operations (mperham)
256
- - Add incr and decr operations (mperham)
257
- - Initial support for SASL authentication via the MEMCACHE_{USERNAME,PASSWORD} environment variables, needed for Heroku (mperham)
258
-
259
- 0.9.0
260
- -----
261
-
262
- - Initial gem release.
data/Performance.md DELETED
@@ -1,42 +0,0 @@
1
- Performance
2
- ====================
3
-
4
- Caching is all about performance, so I carefully track Dalli performance to ensure no regressions.
5
- You can optionally use kgio to give Dalli a 10-20% performance boost: `gem install kgio`.
6
-
7
- Note I've added some benchmarks over time to Dalli that the other libraries don't necessarily have.
8
-
9
- memcache-client
10
- ---------------
11
-
12
- Testing 1.8.5 with ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]
13
-
14
- user system total real
15
- set:plain:memcache-client 1.860000 0.310000 2.170000 ( 2.188030)
16
- set:ruby:memcache-client 1.830000 0.290000 2.120000 ( 2.130212)
17
- get:plain:memcache-client 1.830000 0.340000 2.170000 ( 2.176156)
18
- get:ruby:memcache-client 1.900000 0.330000 2.230000 ( 2.235045)
19
- multiget:ruby:memcache-client 0.860000 0.120000 0.980000 ( 0.987348)
20
- missing:ruby:memcache-client 1.630000 0.320000 1.950000 ( 1.954867)
21
- mixed:ruby:memcache-client 3.690000 0.670000 4.360000 ( 4.364469)
22
-
23
-
24
- dalli
25
- -----
26
-
27
- Testing with Rails 3.2.1
28
- Using kgio socket IO
29
- Testing 2.0.0 with ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]
30
-
31
- user system total real
32
- mixed:rails:dalli 1.580000 0.570000 2.150000 ( 3.008839)
33
- set:plain:dalli 0.730000 0.300000 1.030000 ( 1.567098)
34
- setq:plain:dalli 0.520000 0.120000 0.640000 ( 0.634402)
35
- set:ruby:dalli 0.800000 0.300000 1.100000 ( 1.640348)
36
- get:plain:dalli 0.840000 0.330000 1.170000 ( 1.668425)
37
- get:ruby:dalli 0.850000 0.330000 1.180000 ( 1.665716)
38
- multiget:ruby:dalli 0.700000 0.260000 0.960000 ( 0.965423)
39
- missing:ruby:dalli 0.720000 0.320000 1.040000 ( 1.511720)
40
- mixed:ruby:dalli 1.660000 0.640000 2.300000 ( 3.320743)
41
- mixedq:ruby:dalli 1.630000 0.510000 2.140000 ( 2.629734)
42
- incr:ruby:dalli 0.270000 0.100000 0.370000 ( 0.547618)
data/Rakefile DELETED
@@ -1,39 +0,0 @@
1
- require 'rake/testtask'
2
- Rake::TestTask.new(:test) do |test|
3
- test.libs << 'test'
4
- test.pattern = 'test/**/test_*.rb'
5
- end
6
-
7
- Rake::TestTask.new(:bench) do |test|
8
- test.libs << 'test'
9
- test.pattern = 'test/benchmark_test.rb'
10
- end
11
-
12
- begin
13
- require 'metric_fu'
14
- MetricFu::Configuration.run do |config|
15
- config.rcov[:rcov_opts] << "-Itest:lib"
16
- end
17
- rescue LoadError
18
- end
19
-
20
- task :default => :test
21
-
22
- task :test_all do
23
- system('rake test RAILS_VERSION="~> 3.0.0"')
24
- system('rake test RAILS_VERSION=">= 3.0.0"')
25
- end
26
-
27
- # 'gem install rdoc' to upgrade RDoc if this is giving you errors
28
- begin
29
- require 'rdoc/task'
30
- RDoc::Task.new do |rd|
31
- rd.rdoc_files.include("lib/**/*.rb")
32
- end
33
- rescue LoadError
34
- puts "Unable to load rdoc, run 'gem install rdoc' to fix this."
35
- end
36
-
37
- require 'rake/clean'
38
- CLEAN.include "**/*.rbc"
39
- CLEAN.include "**/.DS_Store"
data/dalli.gemspec DELETED
@@ -1,28 +0,0 @@
1
- require './lib/dalli/version'
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{dalli}
5
- s.version = Dalli::VERSION
6
-
7
- s.authors = ["Mike Perham"]
8
- s.description = %q{High performance memcached client for Ruby}
9
- s.email = %q{mperham@gmail.com}
10
- s.files = Dir.glob("lib/**/*") + [
11
- "LICENSE",
12
- "README.md",
13
- "History.md",
14
- "Rakefile",
15
- "Gemfile",
16
- "dalli.gemspec",
17
- "Performance.md",
18
- ]
19
- s.homepage = %q{http://github.com/mperham/dalli}
20
- s.rdoc_options = ["--charset=UTF-8"]
21
- s.require_paths = ["lib"]
22
- s.summary = %q{High performance memcached client for Ruby}
23
- s.test_files = Dir.glob("test/**/*")
24
- s.add_development_dependency(%q<mini_shoulda>, [">= 0"])
25
- s.add_development_dependency(%q<mocha>, [">= 0"])
26
- s.add_development_dependency(%q<rails>, ["~> 3"])
27
- end
28
-
@@ -1,76 +0,0 @@
1
- require 'active_support/cache'
2
- require 'action_dispatch/middleware/session/abstract_store'
3
- require 'dalli'
4
-
5
- # Dalli-based session store for Rails 3.0.
6
- module ActionDispatch
7
- module Session
8
- class DalliStore < AbstractStore
9
- def initialize(app, options = {})
10
- # Support old :expires option
11
- options[:expire_after] ||= options[:expires]
12
-
13
- super
14
-
15
- @default_options = { :namespace => 'rack:session' }.merge(@default_options)
16
-
17
- @pool = options[:cache] || begin
18
- Dalli::Client.new(
19
- @default_options[:memcache_server], @default_options)
20
- end
21
- @namespace = @default_options[:namespace]
22
-
23
- super
24
- end
25
-
26
- def reset
27
- @pool.reset
28
- end
29
-
30
- private
31
-
32
- def get_session(env, sid)
33
- sid ||= generate_sid
34
- begin
35
- session = @pool.get(sid) || {}
36
- rescue Dalli::DalliError => ex
37
- # re-raise ArgumentError so Rails' session abstract_store.rb can autoload any missing models
38
- raise ArgumentError, ex.message if ex.message =~ /unmarshal/
39
- Rails.logger.warn("Session::DalliStore#get: #{ex.message}")
40
- session = {}
41
- end
42
- [sid, session]
43
- end
44
-
45
- def set_session(env, sid, session_data, options = nil)
46
- options ||= env[ENV_SESSION_OPTIONS_KEY]
47
- expiry = options[:expire_after]
48
- @pool.set(sid, session_data, expiry)
49
- sid
50
- rescue Dalli::DalliError
51
- Rails.logger.warn("Session::DalliStore#set: #{$!.message}")
52
- false
53
- end
54
-
55
- def destroy_session(env, session_id, options)
56
- begin
57
- @pool.delete(session_id)
58
- rescue Dalli::DalliError
59
- Rails.logger.warn("Session::DalliStore#destroy_session: #{$!.message}")
60
- end
61
- return nil if options[:drop]
62
- generate_sid
63
- end
64
-
65
- def destroy(env)
66
- if sid = current_session_id(env)
67
- @pool.delete(sid)
68
- end
69
- rescue Dalli::DalliError
70
- Rails.logger.warn("Session::DalliStore#destroy: #{$!.message}")
71
- false
72
- end
73
-
74
- end
75
- end
76
- end