sayso-dalli 1.0.3.001

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'simplecov'
7
+ end
data/History.md ADDED
@@ -0,0 +1,175 @@
1
+ Dalli Changelog
2
+ =====================
3
+
4
+ HEAD
5
+ =======
6
+
7
+ - Handle non-ASCII key content in dalli_store
8
+ - Accept key array for read_multi in dalli_store
9
+
10
+ 1.0.3
11
+ =======
12
+
13
+ - Better handling of application marshalling errors
14
+ - Work around jruby IO#sysread compatibility issue
15
+
16
+
17
+ 1.0.2
18
+ =======
19
+
20
+ - Allow browser session cookies (blindsey)
21
+ - Compatibility fixes (mwynholds)
22
+ - Add backwards compatibility module for memcache-client, require 'dalli/memcache-client'. It makes
23
+ Dalli more compatible with memcache-client and prints out a warning any time you do something that
24
+ is no longer supported so you can fix your code.
25
+
26
+ 1.0.1
27
+ =======
28
+
29
+ - Explicitly handle application marshalling bugs, GH-56
30
+ - Add support for username/password as options, to allow multiple bucket access
31
+ from the same Ruby process, GH-52
32
+ - Add support for >1MB values with :value_max_bytes option, GH-54 (r-stu31)
33
+ - Add support for default TTL, :expires_in, in Rails 2.3. (Steven Novotny)
34
+ config.cache_store = :dalli_store, 'localhost:11211', {:expires_in => 4.hours}
35
+
36
+
37
+ 1.0.0
38
+ =======
39
+
40
+ Welcome gucki as a Dalli committer!
41
+
42
+ - Fix network and namespace issues in get_multi (gucki)
43
+ - Better handling of unmarshalling errors (mperham)
44
+
45
+ 0.11.2
46
+ =======
47
+
48
+ - Major reworking of socket error and failover handling (gucki)
49
+ - Add basic JRuby support (mperham)
50
+
51
+ 0.11.1
52
+ ======
53
+
54
+ - Minor fixes, doc updates.
55
+ - Add optional support for kgio sockets, gives a 10-15% performance boost.
56
+
57
+ 0.11.0
58
+ ======
59
+
60
+ 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.
61
+
62
+ IT IS HIGHLY RECOMMENDED YOU FLUSH YOUR CACHE BEFORE UPGRADING.
63
+
64
+ - multi() now works reentrantly.
65
+ - Added new Dalli::Client option for default TTLs, :expires_in, defaults to 0 (aka forever).
66
+ - Added new Dalli::Client option, :compression, to enable auto-compression of values.
67
+ - Refactor how Dalli stores data on the server. Values are now tagged
68
+ as "marshalled" or "compressed" so they can be automatically deserialized
69
+ without the client having to know how they were stored.
70
+
71
+ 0.10.1
72
+ ======
73
+
74
+ - Prefer server config from environment, fixes Heroku session store issues (thanks JoshMcKin)
75
+ - Better handling of non-ASCII values (size -> bytesize)
76
+ - Assert that keys are ASCII only
77
+
78
+ 0.10.0
79
+ ======
80
+
81
+ 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.
82
+
83
+ IT IS HIGHLY RECOMMENDED YOU FLUSH YOUR CACHE BEFORE UPGRADING.
84
+
85
+ - Rework how the Rails cache store does value marshalling.
86
+ - Rework old server version detection to avoid a socket read hang.
87
+ - Refactor the Rails 2.3 :dalli\_store to be closer to :mem\_cache\_store.
88
+ - Better documentation for session store config (plukevdh)
89
+
90
+ 0.9.10
91
+ ----
92
+
93
+ - Better server retry logic (next2you)
94
+ - Rails 3.1 compatibility (gucki)
95
+
96
+
97
+ 0.9.9
98
+ ----
99
+
100
+ - Add support for *_multi operations for add, set, replace and delete. This implements
101
+ pipelined network operations; Dalli disables network replies so we're not limited by
102
+ latency, allowing for much higher throughput.
103
+
104
+ dc = Dalli::Client.new
105
+ dc.multi do
106
+ dc.set 'a', 1
107
+ dc.set 'b', 2
108
+ dc.set 'c', 3
109
+ dc.delete 'd'
110
+ end
111
+ - Minor fix to set the continuum sorted by value (kangster)
112
+ - Implement session store with Rails 2.3. Update docs.
113
+
114
+ 0.9.8
115
+ -----
116
+
117
+ - Implement namespace support
118
+ - Misc fixes
119
+
120
+
121
+ 0.9.7
122
+ -----
123
+
124
+ - Small fix for NewRelic integration.
125
+ - Detect and fail on older memcached servers (pre-1.4).
126
+
127
+ 0.9.6
128
+ -----
129
+
130
+ - Patches for Rails 3.0.1 integration.
131
+
132
+ 0.9.5
133
+ -----
134
+
135
+ - Major design change - raw support is back to maximize compatibility with Rails
136
+ and the increment/decrement operations. You can now pass :raw => true to most methods
137
+ to bypass (un)marshalling.
138
+ - Support symbols as keys (ddollar)
139
+ - Rails 2.3 bug fixes
140
+
141
+
142
+ 0.9.4
143
+ -----
144
+
145
+ - Dalli support now in rack-bug (http://github.com/brynary/rack-bug), give it a try!
146
+ - Namespace support for Rails 2.3 (bpardee)
147
+ - Bug fixes
148
+
149
+
150
+ 0.9.3
151
+ -----
152
+
153
+ - Rails 2.3 support (beanieboi)
154
+ - Rails SessionStore support
155
+ - Passenger integration
156
+ - memcache-client upgrade docs, see Upgrade.md
157
+
158
+
159
+ 0.9.2
160
+ ----
161
+
162
+ - Verify proper operation in Heroku.
163
+
164
+
165
+ 0.9.1
166
+ ----
167
+
168
+ - Add fetch and cas operations (mperham)
169
+ - Add incr and decr operations (mperham)
170
+ - Initial support for SASL authentication via the MEMCACHE_{USERNAME,PASSWORD} environment variables, needed for Heroku (mperham)
171
+
172
+ 0.9.0
173
+ -----
174
+
175
+ - Initial gem release.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Mike Perham
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Performance.md ADDED
@@ -0,0 +1,77 @@
1
+ Performance
2
+ ====================
3
+
4
+ Caching is all about performance, so I carefully track Dalli performance to ensure no regressions.
5
+ Times are from a Unibody MBP 2.4Ghz Core i5 running Snow Leopard.
6
+
7
+ You can optionally use kgio to give Dalli a small, 10-20% performance boost: gem install kgio.
8
+
9
+ *memcache-client*:
10
+
11
+ Testing 1.8.5 with ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.6.0]
12
+ user system total real
13
+ set:plain:memcache 2.070000 0.340000 2.410000 ( 2.611709)
14
+ set:ruby:memcache 1.990000 0.330000 2.320000 ( 2.869653)
15
+ get:plain:memcache 2.290000 0.360000 2.650000 ( 2.926425)
16
+ get:ruby:memcache 2.360000 0.350000 2.710000 ( 2.951604)
17
+ multiget:ruby:memcache 1.050000 0.120000 1.170000 ( 1.285787)
18
+ missing:ruby:memcache 1.990000 0.330000 2.320000 ( 2.567641)
19
+ mixed:ruby:memcache 4.390000 0.670000 5.060000 ( 5.721000)
20
+ incr:ruby:memcache 0.700000 0.120000 0.820000 ( 0.842896)
21
+
22
+ *libmemcached*:
23
+
24
+ Testing 1.1.2 with ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.6.0]
25
+ user system total real
26
+ set:plain:libm 0.120000 0.220000 0.340000 ( 0.847521)
27
+ setq:plain:libm 0.030000 0.000000 0.030000 ( 0.126944)
28
+ set:ruby:libm 0.220000 0.250000 0.470000 ( 1.102789)
29
+ get:plain:libm 0.140000 0.230000 0.370000 ( 0.813998)
30
+ get:ruby:libm 0.210000 0.240000 0.450000 ( 1.025994)
31
+ multiget:ruby:libm 0.100000 0.080000 0.180000 ( 0.322217)
32
+ missing:ruby:libm 0.250000 0.240000 0.490000 ( 1.049972)
33
+ mixed:ruby:libm 0.400000 0.410000 0.810000 ( 2.172349)
34
+ mixedq:ruby:libm 0.410000 0.360000 0.770000 ( 1.516718)
35
+ incr:ruby:libm 0.080000 0.340000 0.420000 ( 1.685931)
36
+
37
+ *dalli*:
38
+
39
+ Using kgio socket IO
40
+ Testing 1.0.2 with ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.6.0]
41
+ user system total real
42
+ set:plain:dalli 0.850000 0.320000 1.170000 ( 1.691393)
43
+ setq:plain:dalli 0.500000 0.130000 0.630000 ( 0.651227)
44
+ set:ruby:dalli 0.900000 0.330000 1.230000 ( 1.865228)
45
+ get:plain:dalli 0.990000 0.390000 1.380000 ( 1.929994)
46
+ get:ruby:dalli 0.950000 0.370000 1.320000 ( 1.844251)
47
+ multiget:ruby:dalli 0.790000 0.300000 1.090000 ( 1.227073)
48
+ missing:ruby:dalli 0.810000 0.370000 1.180000 ( 1.627039)
49
+ mixed:ruby:dalli 1.850000 0.710000 2.560000 ( 3.555032)
50
+ mixedq:ruby:dalli 1.840000 0.610000 2.450000 ( 2.945982)
51
+ incr:ruby:dalli 0.310000 0.120000 0.430000 ( 0.616465)
52
+
53
+ Testing 1.0.2 with rubinius 1.3.0dev (1.8.7 382e813f xxxx-xx-xx JI) [x86_64-apple-darwin10.6.0]
54
+ user system total real
55
+ set:plain:dalli 2.800581 0.329360 3.129941 ( 5.186546)
56
+ setq:plain:dalli 1.064253 0.138044 1.202297 ( 1.280355)
57
+ set:ruby:dalli 2.220885 0.262619 2.483504 ( 2.778118)
58
+ get:plain:dalli 2.291344 0.280490 2.571834 ( 2.948004)
59
+ get:ruby:dalli 2.148900 0.274477 2.423377 ( 2.425808)
60
+ multiget:ruby:dalli 1.724193 0.249145 1.973338 ( 2.158673)
61
+ missing:ruby:dalli 1.881502 0.272610 2.154112 ( 2.208384)
62
+ mixed:ruby:dalli 4.292620 0.533768 4.826388 ( 4.830238)
63
+ mixedq:ruby:dalli 4.076032 0.501442 4.577474 ( 4.583800)
64
+ incr:ruby:dalli 0.691467 0.091475 0.782942 ( 0.931674)
65
+
66
+ Testing 1.0.2 with rubinius 1.2.0 (1.8.7 release 2010-12-21 JI) [x86_64-apple-darwin10.6.0]
67
+ user system total real
68
+ set:plain:dalli 6.586927 0.331545 6.918472 ( 4.628652)
69
+ setq:plain:dalli 0.930905 0.129008 1.059913 ( 1.016105)
70
+ set:ruby:dalli 2.702486 0.283004 2.985490 ( 2.690442)
71
+ get:plain:dalli 2.740202 0.291353 3.031555 ( 2.722746)
72
+ get:ruby:dalli 1.979379 0.282986 2.262365 ( 2.264118)
73
+ multiget:ruby:dalli 1.887086 0.249799 2.136885 ( 1.803230)
74
+ missing:ruby:dalli 1.882662 0.278019 2.160681 ( 2.113429)
75
+ mixed:ruby:dalli 3.969242 0.553361 4.522603 ( 4.524504)
76
+ mixedq:ruby:dalli 3.520755 0.475669 3.996424 ( 3.997405)
77
+ incr:ruby:dalli 0.849998 0.094012 0.944010 ( 0.884001)
data/README.md ADDED
@@ -0,0 +1,177 @@
1
+ Dalli
2
+ =========
3
+
4
+ Dalli is a high performance pure Ruby client for accessing memcached servers. It works with memcached 1.4+ only as it uses the newer binary protocol. It should be considered a replacement for the memcache-client gem. The API tries to be mostly compatible with memcache-client with the goal being to make it a drop-in replacement for Rails.
5
+
6
+ The name is a variant of Salvador Dali for his famous painting [The Persistence of Memory](http://en.wikipedia.org/wiki/The_Persistence_of_Memory).
7
+
8
+ ![Persistence of Memory](http://www.virtualdali.com/assets/paintings/31PersistenceOfMemory.jpg)
9
+
10
+ Dalli's development is sponsored by [Membase](http://www.membase.com/). Many thanks to them!
11
+
12
+
13
+ Design
14
+ ------------
15
+
16
+ I decided to write Dalli after maintaining memcache-client for the last two years for a few specific reasons:
17
+
18
+ 0. The code is mostly old and gross. The bulk of the code is a single 1000 line .rb file.
19
+ 1. It has a lot of options that are infrequently used which complicate the codebase.
20
+ 2. The implementation has no single point to attach monitoring hooks.
21
+ 3. Uses the old text protocol, which hurts raw performance.
22
+
23
+ So a few notes. Dalli:
24
+
25
+ 0. uses the exact same algorithm to choose a server so existing memcached clusters with TBs of data will work identically to memcache-client.
26
+ 1. is approximately 20% faster than memcache-client (which itself was heavily optimized) in Ruby 1.9.2.
27
+ 2. contains explicit "chokepoint" methods which handle all requests; these can be hooked into by monitoring tools (NewRelic, Rack::Bug, etc) to track memcached usage.
28
+ 3. comes with hooks to replace memcache-client in Rails.
29
+ 4. is approx 700 lines of Ruby. memcache-client is approx 1250 lines.
30
+ 5. supports SASL for use in managed environments, e.g. Heroku.
31
+ 6. provides proper failover with recovery and adjustable timeouts
32
+ 7. has a backwards-compatibility mode for people migrating from memcache-client (see Upgrade.md).
33
+
34
+
35
+ Installation and Usage
36
+ ------------------------
37
+
38
+ Remember, Dalli **requires** memcached 1.4+. You can check the version with `memcached -h`.
39
+
40
+ gem install dalli
41
+
42
+ require 'dalli'
43
+ dc = Dalli::Client.new('localhost:11211')
44
+ dc.set('abc', 123)
45
+ value = dc.get('abc')
46
+
47
+ The test suite requires memcached 1.4.3+ with SASL enabled (brew install memcached --enable-sasl ; mv /usr/bin/memcache /usr/bin/memcached.old). Currently only supports the PLAIN mechanism.
48
+
49
+ Dalli has no runtime dependencies and never will. You can optionally install the 'kgio' gem to
50
+ give Dalli a 10-20% performance boost.
51
+
52
+
53
+ Usage with Rails 3.0
54
+ ---------------------------
55
+
56
+ In your Gemfile:
57
+
58
+ gem 'dalli'
59
+
60
+ In `config/environments/production.rb`:
61
+
62
+ config.cache_store = :dalli_store
63
+
64
+ A more comprehensive example (note that we are setting a reasonable default for maximum cache entry lifetime (one day), enabling compression for large values, and namespacing all entries for this rails app. Remove the namespace if you have multiple apps which share cached values):
65
+
66
+ config.cache_store = :dalli_store, 'cache-1.example.com', 'cache-2.example.com',
67
+ { :namespace => NAME_OF_RAILS_APP, :expires_in => 1.day, :compress => true }
68
+
69
+ To use Dalli for Rails session storage, in `config/initializers/session_store.rb`:
70
+
71
+ require 'action_dispatch/middleware/session/dalli_store'
72
+ Rails.application.config.session_store :dalli_store, :memcache_server => ['host1', 'host2'], :namespace => 'sessions', :key => '_foundation_session', :expire_after => 30.minutes
73
+
74
+
75
+ Usage with Rails 2.3.x
76
+ ----------------------------
77
+
78
+ In `config/environment.rb`:
79
+
80
+ config.gem 'dalli'
81
+
82
+ In `config/environments/production.rb`:
83
+
84
+ # Object cache
85
+ require 'active_support/cache/dalli_store23'
86
+ config.cache_store = :dalli_store
87
+
88
+ In `config/initializers/session_store.rb`:
89
+
90
+ # Session cache
91
+ ActionController::Base.session = {
92
+ :namespace => 'sessions',
93
+ :expire_after => 20.minutes.to_i,
94
+ :memcache_server => ['server-1:11211', 'server-2:11211'],
95
+ :key => ...,
96
+ :secret => ...
97
+ }
98
+
99
+ require 'action_controller/session/dalli_store'
100
+ ActionController::Base.session_store = :dalli_store
101
+
102
+
103
+ Usage with Passenger
104
+ ------------------------
105
+
106
+ Put this at the bottom of `config/environment.rb`:
107
+
108
+ if defined?(PhusionPassenger)
109
+ PhusionPassenger.on_event(:starting_worker_process) do |forked|
110
+ # Only works with DalliStore
111
+ Rails.cache.reset if forked
112
+ end
113
+ end
114
+
115
+
116
+ Configuration
117
+ ------------------------
118
+ Dalli::Client accepts the following options. All times are in seconds.
119
+
120
+ **expires_in**: Global default for key TTL. No default.
121
+
122
+ **failover**: Boolean, if true Dalli will failover to another server if the main server for a key is down.
123
+
124
+ **compression**: Boolean, if true Dalli will gzip-compress values larger than 1K.
125
+
126
+ **socket_timeout**: Timeout for all socket operations (connect, read, write). Default is 0.5.
127
+
128
+ **socket_max_failures**: When a socket operation fails after socket_timeout, the same operation is retried. This is to not immediately mark a server down when there's a very slight network problem. Default is 2.
129
+
130
+ **socket_failure_delay**: Before retrying a socket operation, the process sleeps for this amount of time. Default is 0.01. Set to nil for no delay.
131
+
132
+ **down_retry_delay**: When a server has been marked down due to many failures, the server will be checked again for being alive only after this amount of time. Don't set this value to low, otherwise each request which tries the failed server might hang for the maximum **socket_timeout**. Default is 1 second.
133
+
134
+ **value_max_bytes**: The maximum size of a value in memcached. Defaults to 1MB, this can be increased with memcached's -I parameter. You must also configure Dalli to allow the larger size here.
135
+
136
+ **username**: The username to use for authenticating this client instance against a SASL-enabled memcached server. Heroku users should not need to use this normally.
137
+
138
+ **password**: The password to use for authenticating this client instance against a SASL-enabled memcached server. Heroku users should not need to use this normally.
139
+
140
+ Features and Changes
141
+ ------------------------
142
+
143
+ Dalli is **NOT** 100% API compatible with memcache-client. If you have code which uses the MemCache API directly, it will likely need small tweaks. Method parameters and return values changed slightly. See Upgrade.md for more detail.
144
+
145
+ By default, Dalli is thread-safe. Disable thread-safety at your own peril.
146
+
147
+ Note that Dalli does not require ActiveSupport or Rails. You can safely use it in your own Ruby projects.
148
+
149
+
150
+ Helping Out
151
+ -------------
152
+
153
+ If you have a fix you wish to provide, please fork the code, fix in your local project and then send a pull request on github. Please ensure that you include a test which verifies your fix and update History.md with a one sentence description of your fix so you get credit as a contributor.
154
+
155
+
156
+ Thanks
157
+ ------------
158
+
159
+ Eric Wong - for help using his [kgio](http://unicorn.bogomips.org/kgio/index.html) library.
160
+
161
+ Brian Mitchell - for his remix-stash project which was helpful when implementing and testing the binary protocol support.
162
+
163
+ [Membase](http://membase.com) - for their project sponsorship
164
+
165
+ [Bootspring](http://bootspring.com) is my Ruby and Rails consulting company. We specialize in Ruby infrastructure, performance and scalability tuning for Rails applications. If you need help, please [contact us](mailto:info@bootspring.com) today.
166
+
167
+
168
+ Author
169
+ ----------
170
+
171
+ Mike Perham, mperham@gmail.com, [mikeperham.com](http://mikeperham.com), [@mperham](http://twitter.com/mperham) If you like and use this project, please give me a recommendation at [WWR](http://workingwithrails.com/person/10797-mike-perham). Happy caching!
172
+
173
+
174
+ Copyright
175
+ -----------
176
+
177
+ Copyright (c) 2010 Mike Perham. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
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="~> 2.3.0"')
24
+ system('rake test RAILS_VERSION="~> 3.0.0"')
25
+ end
26
+
27
+ require 'rake/rdoctask'
28
+ Rake::RDocTask.new do |rd|
29
+ rd.rdoc_files.include("lib/**/*.rb")
30
+ end
31
+
32
+ require 'rake/clean'
33
+ CLEAN.include "**/*.rbc"
34
+ CLEAN.include "**/.DS_Store"
data/Upgrade.md ADDED
@@ -0,0 +1,45 @@
1
+ Upgrading from memcache-client
2
+ ========
3
+
4
+ Dalli is not meant to be 100% compatible with memcache-client, there are a few minor differences in the API.
5
+
6
+
7
+ Compatibility Layer
8
+ ----------------------
9
+
10
+ Enable memcache-client compatibility in your application when upgrading by requiring this when
11
+ initalizing your app:
12
+
13
+ require 'dalli/memcache-client'
14
+
15
+ This will print out warnings if your code is using the old memcache-client API style, explained below.
16
+
17
+
18
+ Marshalling
19
+ ---------------
20
+
21
+ Dalli has changed the raw parameter to a :raw option. The memcache-client API allowed you to control marshalling on a per-method basis using a boolean 'raw' parameter to several of the API methods:
22
+
23
+ cache = MemCache.new
24
+ cache.set('abc', 123, 0, true)
25
+ cache.get('abc', true) => '123'
26
+
27
+ cache.set('abc', 123, 0)
28
+ cache.get('abc') => 123
29
+
30
+ Note that the last parameter is set to true in the first two API calls and so `get` returns a string, not an integer. In the second example, we don't provide the raw parameter. Since it defaults to false, it works exactly like Dalli.
31
+
32
+ If the code specifies raw as false, you can simply remove that parameter. If the code is using raw = true, you will need to use the :raw option:
33
+
34
+ cache.set('abc', 123, 0, :raw => true)
35
+
36
+
37
+ Return Values
38
+ ----------------
39
+
40
+ In memcache-client, `set(key, value)` normally returns "STORED\r\n". This is an artifact of the text protocol used in earlier versions of memcached. Code that checks the return value will need to be updated. Dalli raises errors for exceptional cases but otherwise returns true or false depending on whether the operation succeeded or not. These methods are affected:
41
+
42
+ set
43
+ add
44
+ replace
45
+ delete
data/dalli.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ lib = File.expand_path('../lib/', __FILE__)
2
+ $:.unshift lib unless $:.include?(lib)
3
+ require 'dalli/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{sayso-dalli}
7
+ s.version = Dalli::VERSION
8
+
9
+ s.authors = ["SaySo"]
10
+ s.date = Time.now.utc.strftime("%Y-%m-%d")
11
+ s.description = %q{High performance memcached client for Ruby - forked and gemified for sayso}
12
+ s.email = %q{sayso@truvolabs.com}
13
+ s.files = Dir.glob("lib/**/*") + [
14
+ "LICENSE",
15
+ "README.md",
16
+ "History.md",
17
+ "Rakefile",
18
+ "Gemfile",
19
+ "dalli.gemspec",
20
+ "Performance.md",
21
+ "Upgrade.md",
22
+ ]
23
+ s.homepage = %q{http://github.com/sayso/dalli}
24
+ s.rdoc_options = ["--charset=UTF-8"]
25
+ s.require_paths = ["lib"]
26
+ s.summary = %q{High performance memcached client for Ruby - forked and gemified for sayso}
27
+ s.test_files = Dir.glob("test/**/*")
28
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
29
+ s.add_development_dependency(%q<mocha>, [">= 0"])
30
+ s.add_development_dependency(%q<rails>, [">= 3.0.1"])
31
+ s.add_development_dependency(%q<memcache-client>, [">= 1.8.5"])
32
+ end
33
+
@@ -0,0 +1,62 @@
1
+ # Session store for Rails 2.3.x
2
+ # Tested against 2.3.9.
3
+ begin
4
+ require_library_or_gem 'dalli'
5
+
6
+ module ActionController
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 = {
16
+ :namespace => 'rack:session',
17
+ :memcache_server => 'localhost:11211'
18
+ }.merge(@default_options)
19
+
20
+ Rails.logger.debug("Using Dalli #{Dalli::VERSION} for session store at #{@default_options[:memcache_server].inspect}")
21
+
22
+ @pool = Dalli::Client.new(@default_options[:memcache_server], @default_options)
23
+ super
24
+ end
25
+
26
+ private
27
+ def get_session(env, sid)
28
+ sid ||= generate_sid
29
+ begin
30
+ session = @pool.get(sid) || {}
31
+ rescue Dalli::DalliError
32
+ Rails.logger.warn("Session::DalliStore#get: #{$!.message}")
33
+ session = {}
34
+ end
35
+ [sid, session]
36
+ end
37
+
38
+ def set_session(env, sid, session_data)
39
+ options = env['rack.session.options']
40
+ expiry = options[:expire_after]
41
+ @pool.set(sid, session_data, expiry)
42
+ return true
43
+ rescue Dalli::DalliError
44
+ Rails.logger.warn("Session::DalliStore#set: #{$!.message}")
45
+ return false
46
+ end
47
+
48
+ def destroy(env)
49
+ if sid = current_session_id(env)
50
+ @pool.delete(sid)
51
+ end
52
+ rescue Dalli::DalliError
53
+ Rails.logger.warn("Session::DalliStore#destroy: #{$!.message}")
54
+ false
55
+ end
56
+
57
+ end
58
+ end
59
+ end
60
+ rescue LoadError
61
+ # Dalli wasn't available so neither can the store be
62
+ end