dalli 2.7.10 → 3.0.2
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.
- checksums.yaml +4 -4
- data/Gemfile +7 -2
- data/History.md +52 -2
- data/README.md +25 -111
- data/lib/dalli/cas/client.rb +1 -59
- data/lib/dalli/client.rb +178 -108
- data/lib/dalli/compressor.rb +4 -3
- data/lib/dalli/options.rb +3 -4
- data/lib/dalli/protocol/binary.rb +753 -0
- data/lib/dalli/protocol.rb +9 -0
- data/lib/dalli/ring.rb +12 -63
- data/lib/dalli/server.rb +2 -745
- data/lib/dalli/socket.rb +62 -128
- data/lib/dalli/version.rb +2 -1
- data/lib/dalli.rb +15 -17
- data/lib/rack/session/dalli.rb +21 -40
- metadata +11 -83
- data/lib/action_dispatch/middleware/session/dalli_store.rb +0 -82
- data/lib/active_support/cache/dalli_store.rb +0 -435
- data/lib/dalli/railtie.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fadd6651330b2d8455d781253451bd4e47d6caaaad9c12002284c6541727adb
|
4
|
+
data.tar.gz: ea65f2d7199c5dea247c2909ac90775240bd3da1ccfaebcebc916788a8b0ebf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 368db20ef7ceb7a8301e8e027107ce90b238295f59aa8e1412f1e34a30a0e903ae56b6a07b2963eee0bc1a540fded0cacd3092a02f25ad1c17a21a05320baaf3
|
7
|
+
data.tar.gz: 32cc139bc122233910dddb62e1e3a6e1efec95e19d181dab04c8ced725806e238e1e6a62797cbbd8336e6e16b4a4a394c2f937bcaf8fffa63f66149d9f598e8c
|
data/Gemfile
CHANGED
data/History.md
CHANGED
@@ -1,12 +1,62 @@
|
|
1
1
|
Dalli Changelog
|
2
2
|
=====================
|
3
3
|
|
4
|
+
3.0.2
|
5
|
+
==========
|
6
|
+
|
7
|
+
- Restore Windows compatibility (petergoldstein)
|
8
|
+
- Add JRuby to CI and make requisite changes (petergoldstein)
|
9
|
+
- Clarify documentation for supported rubies (petergoldstein)
|
10
|
+
|
11
|
+
3.0.1
|
12
|
+
==========
|
13
|
+
|
14
|
+
- Fix syntax error that prevented inclusion of Dalli::Server (ryanfb)
|
15
|
+
- Restore with method required by ActiveSupport::Cache::MemCacheStore
|
16
|
+
|
17
|
+
3.0.0
|
18
|
+
==========
|
19
|
+
- BREAKING CHANGES:
|
20
|
+
|
21
|
+
* Removes :dalli_store.
|
22
|
+
Use Rails' official :mem_cache_store instead.
|
23
|
+
https://guides.rubyonrails.org/caching_with_rails.html
|
24
|
+
* Attempting to store a larger value than allowed by memcached used to
|
25
|
+
print a warning and truncate the value. This now raises an error to
|
26
|
+
prevent silent data corruption.
|
27
|
+
* Compression now defaults to `true` for large values (greater than 4KB).
|
28
|
+
This is intended to minimize errors due to the previous note.
|
29
|
+
* Errors marshalling values now raise rather than just printing an error.
|
30
|
+
* The Rack session adapter has been refactored to remove support for thread-unsafe
|
31
|
+
configurations. You will need to include the `connection_pool` gem in
|
32
|
+
your Gemfile to ensure session operations are thread-safe.
|
33
|
+
|
34
|
+
- Raise NetworkError when multi response gets into corrupt state (mervync, #783)
|
35
|
+
- Validate servers argument (semaperepelitsa, petergoldstein, #776)
|
36
|
+
- Enable SSL support (bdunne, #775)
|
37
|
+
- Add gat operation (tbeauvais, #769)
|
38
|
+
- Removes inline native code, use Ruby 2.3+ support for bsearch instead. (mperham)
|
39
|
+
- Switch repo to Github Actions and upgrade Ruby versions (petergoldstein, bdunne, Fryguy)
|
40
|
+
- Update benchmark test for Rubyprof changes (nateberkopec)
|
41
|
+
- Remove support for the `kgio` gem, it is not relevant in Ruby 2.3+. (mperham)
|
42
|
+
- Remove inline native code, use Ruby 2.3+ support for bsearch instead. (mperham)
|
43
|
+
|
44
|
+
|
45
|
+
2.7.11
|
46
|
+
==========
|
47
|
+
- DEPRECATION: :dalli_store will be removed in Dalli 3.0.
|
48
|
+
Use Rails' official :mem_cache_store instead.
|
49
|
+
https://guides.rubyonrails.org/caching_with_rails.html
|
50
|
+
- Add new `digest_class` option to Dalli::Client [#724]
|
51
|
+
- Don't treat NameError as a network error [#728]
|
52
|
+
- Handle nested comma separated server strings (sambostock)
|
53
|
+
|
4
54
|
2.7.10
|
5
55
|
==========
|
6
56
|
- Revert frozen string change (schneems)
|
7
57
|
- Advertise supports_cached_versioning? in DalliStore (schneems)
|
8
|
-
- Better detection of fork support, to allow specs to run under Truffle Ruby
|
9
|
-
- Update logging for over max size to log as error
|
58
|
+
- Better detection of fork support, to allow specs to run under Truffle Ruby (deepj)
|
59
|
+
- Update logging for over max size to log as error (aeroastro)
|
10
60
|
|
11
61
|
2.7.9
|
12
62
|
==========
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Dalli [![
|
1
|
+
Dalli [![Tests](https://github.com/petergoldstein/dalli/actions/workflows/tests.yml/badge.svg)](https://github.com/petergoldstein/dalli/actions/workflows/tests.yml)
|
2
2
|
=====
|
3
3
|
|
4
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.
|
@@ -9,34 +9,13 @@ The name is a variant of Salvador Dali for his famous painting [The Persistence
|
|
9
9
|
|
10
10
|
Dalli's initial development was sponsored by [CouchBase](http://www.couchbase.com/). Many thanks to them!
|
11
11
|
|
12
|
-
|
13
|
-
Design
|
14
|
-
------------
|
15
|
-
|
16
|
-
Mike Perham decided to write Dalli after maintaining memcache-client for 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. supports SASL for use in managed environments, e.g. Heroku.
|
29
|
-
4. provides proper failover with recovery and adjustable timeouts
|
30
|
-
|
31
|
-
|
32
12
|
Supported Ruby versions and implementations
|
33
13
|
------------------------------------------------
|
34
14
|
|
35
|
-
Dalli
|
15
|
+
As of Dalli version 3.0 the following Ruby versions are supported:
|
36
16
|
|
37
|
-
*
|
38
|
-
*
|
39
|
-
* Rubinius 2.0
|
17
|
+
* Ruby 2.5.x, 2.6.x, 2.7.x, 3.0.x
|
18
|
+
* JRuby 9.2.x, 9.3.x
|
40
19
|
|
41
20
|
If you have problems, please enter an issue.
|
42
21
|
|
@@ -44,7 +23,7 @@ If you have problems, please enter an issue.
|
|
44
23
|
Installation and Usage
|
45
24
|
------------------------
|
46
25
|
|
47
|
-
Remember, Dalli **requires** memcached 1.4+. You can check the version with `memcached -h`. Please note that the memcached version that *Mac OS X Snow Leopard* ships with is 1.2.8 and it won't work. Install memcached
|
26
|
+
Remember, Dalli **requires** memcached 1.4+. You can check the version with `memcached -h`. Please note that the memcached version that *Mac OS X Snow Leopard* ships with is 1.2.8 and it won't work. Install the most recent version of memcached using Homebrew with
|
48
27
|
|
49
28
|
brew install memcached
|
50
29
|
|
@@ -60,92 +39,29 @@ gem install dalli
|
|
60
39
|
|
61
40
|
```ruby
|
62
41
|
require 'dalli'
|
63
|
-
options = { :
|
42
|
+
options = { namespace: "app_v1", compress: true }
|
64
43
|
dc = Dalli::Client.new('localhost:11211', options)
|
65
44
|
dc.set('abc', 123)
|
66
45
|
value = dc.get('abc')
|
67
46
|
```
|
68
47
|
|
69
|
-
|
70
|
-
|
71
|
-
Dalli has no runtime dependencies and never will. If you are using Ruby <2.3,
|
72
|
-
you can optionally install the '[kgio](https://bogomips.org/kgio/)' gem to
|
73
|
-
give Dalli a 20-30% performance boost.
|
74
|
-
|
75
|
-
|
76
|
-
Usage with Rails 3.x and 4.x
|
77
|
-
---------------------------
|
78
|
-
|
79
|
-
In your Gemfile:
|
80
|
-
|
81
|
-
```ruby
|
82
|
-
gem 'dalli'
|
83
|
-
```
|
84
|
-
|
85
|
-
In `config/environments/production.rb`:
|
86
|
-
|
87
|
-
```ruby
|
88
|
-
config.cache_store = :dalli_store
|
89
|
-
```
|
90
|
-
|
91
|
-
Here's a more comprehensive example that sets a reasonable default for maximum cache entry lifetime (one day), enables compression for large values and namespaces all entries for this rails app. Remove the namespace if you have multiple apps which share cached values.
|
92
|
-
|
48
|
+
With SSL enabled:
|
93
49
|
```ruby
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
```
|
105
|
-
|
106
|
-
To use Dalli for Rails session storage that times out after 20 minutes, in `config/initializers/session_store.rb`:
|
107
|
-
|
108
|
-
For Rails >= 3.2.4:
|
109
|
-
|
110
|
-
```ruby
|
111
|
-
Rails.application.config.session_store ActionDispatch::Session::CacheStore, :expire_after => 20.minutes
|
112
|
-
```
|
113
|
-
|
114
|
-
For Rails 3.x:
|
115
|
-
|
116
|
-
```ruby
|
117
|
-
require 'action_dispatch/middleware/session/dalli_store'
|
118
|
-
Rails.application.config.session_store :dalli_store, :memcache_server => ['host1', 'host2'], :namespace => 'sessions', :key => '_foundation_session', :expire_after => 20.minutes
|
119
|
-
```
|
120
|
-
|
121
|
-
Dalli does not support Rails 2.x.
|
122
|
-
|
123
|
-
|
124
|
-
Multithreading and Rails
|
125
|
-
--------------------------
|
126
|
-
|
127
|
-
If you use Puma or another threaded app server, as of Dalli 2.7, you can use a pool
|
128
|
-
of Dalli clients with Rails to ensure the `Rails.cache` singleton does not become a
|
129
|
-
source of thread contention. You must add `gem 'connection_pool'` to your Gemfile and
|
130
|
-
add :pool\_size to your `dalli_store` config:
|
131
|
-
|
132
|
-
```ruby
|
133
|
-
config.cache_store = :dalli_store, 'cache-1.example.com', { :pool_size => 5 }
|
50
|
+
require 'dalli'
|
51
|
+
ssl_context = OpenSSL::SSL::SSLContext.new
|
52
|
+
ssl_context.ca_file = "./myCA.pem"
|
53
|
+
ssl_context.ssl_version = :SSLv23
|
54
|
+
ssl_context.verify_hostname = true if ssl_context.respond_to?(:verify_hostname=)
|
55
|
+
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
56
|
+
|
57
|
+
dc = Dalli::Client.new("memcached:11212", ssl_context: ssl_context)
|
58
|
+
dc.set("abc", 123)
|
59
|
+
value = dc.get("abc")
|
134
60
|
```
|
135
61
|
|
136
|
-
|
137
|
-
|
138
|
-
```ruby
|
139
|
-
Rails.cache.fetch('foo', :expires_in => 300) do
|
140
|
-
'bar'
|
141
|
-
end
|
142
|
-
|
143
|
-
Rails.cache.dalli.with do |client|
|
144
|
-
# client is a Dalli::Client instance which you can
|
145
|
-
# use ONLY within this block
|
146
|
-
end
|
147
|
-
```
|
62
|
+
The test suite requires memcached 1.4.3+ with SASL enabled (`brew install memcached --enable-sasl ; mv /usr/bin/memcached /usr/bin/memcached.old`). Currently only supports the PLAIN mechanism.
|
148
63
|
|
64
|
+
Dalli has no runtime dependencies.
|
149
65
|
|
150
66
|
Configuration
|
151
67
|
------------------------
|
@@ -160,30 +76,28 @@ Dalli::Client accepts the following options. All times are in seconds.
|
|
160
76
|
|
161
77
|
**failover**: Boolean, if true Dalli will failover to another server if the main server for a key is down. Default is true.
|
162
78
|
|
163
|
-
**threadsafe**: Boolean. If true Dalli ensures that only one thread is using a socket at a given time.
|
79
|
+
**threadsafe**: Boolean. If true Dalli ensures that only one thread is using a socket at a given time. Default is true. You can set to false if you are using the Client within a thread-safe connection pool.
|
164
80
|
|
165
81
|
**serializer**: The serializer to use for objects being stored (ex. JSON).
|
166
82
|
Default is Marshal.
|
167
83
|
|
168
|
-
**compress**: Boolean, if true Dalli will gzip-compress values larger than
|
84
|
+
**compress**: Boolean, if true Dalli will gzip-compress values larger than compression_min_size. Default is true.
|
169
85
|
|
170
86
|
**compression_min_size**: Minimum value byte size for which to attempt compression. Default is 1K.
|
171
87
|
|
172
|
-
**compression_max_size**: Maximum value byte size for which to attempt compression. Default is unlimited.
|
173
|
-
|
174
88
|
**compressor**: The compressor to use for objects being stored.
|
175
89
|
Default is zlib, implemented under `Dalli::Compressor`.
|
176
90
|
If serving compressed data using nginx's HttpMemcachedModule, set `memcached_gzip_flag 2` and use `Dalli::GzipCompressor`
|
177
91
|
|
178
92
|
**keepalive**: Boolean. If true, Dalli will enable keep-alive for socket connections. Default is true.
|
179
93
|
|
180
|
-
**socket_timeout**: Timeout for all socket operations (connect, read, write). Default is
|
94
|
+
**socket_timeout**: Timeout for all socket operations (connect, read, write). Default is 1.
|
181
95
|
|
182
96
|
**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.
|
183
97
|
|
184
|
-
**socket_failure_delay**: Before retrying a socket operation, the process sleeps for this amount of time. Default is 0.
|
98
|
+
**socket_failure_delay**: Before retrying a socket operation, the process sleeps for this amount of time. Default is 0.1. Set to nil for no delay.
|
185
99
|
|
186
|
-
**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 too low, otherwise each request which tries the failed server might hang for the maximum **socket_timeout**. Default is
|
100
|
+
**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 too low, otherwise each request which tries the failed server might hang for the maximum **socket_timeout**. Default is 30 seconds.
|
187
101
|
|
188
102
|
**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.
|
189
103
|
|
@@ -206,7 +120,7 @@ If serving compressed data using nginx's HttpMemcachedModule, set `memcached_gzi
|
|
206
120
|
Features and Changes
|
207
121
|
------------------------
|
208
122
|
|
209
|
-
By default, Dalli is thread-safe.
|
123
|
+
By default, Dalli is thread-safe. Disable thread-safety at your own peril.
|
210
124
|
|
211
125
|
Dalli does not need anything special in Unicorn/Passenger since 2.0.4.
|
212
126
|
It will detect sockets shared with child processes and gracefully reopen the
|
data/lib/dalli/cas/client.rb
CHANGED
@@ -1,59 +1 @@
|
|
1
|
-
|
2
|
-
require 'dalli/client'
|
3
|
-
|
4
|
-
module Dalli
|
5
|
-
class Client
|
6
|
-
##
|
7
|
-
# Get the value and CAS ID associated with the key. If a block is provided,
|
8
|
-
# value and CAS will be passed to the block.
|
9
|
-
def get_cas(key)
|
10
|
-
(value, cas) = perform(:cas, key)
|
11
|
-
value = (!value || value == 'Not found') ? nil : value
|
12
|
-
if block_given?
|
13
|
-
yield value, cas
|
14
|
-
else
|
15
|
-
[value, cas]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
##
|
20
|
-
# Fetch multiple keys efficiently, including available metadata such as CAS.
|
21
|
-
# If a block is given, yields key/data pairs one a time. Data is an array:
|
22
|
-
# [value, cas_id]
|
23
|
-
# If no block is given, returns a hash of
|
24
|
-
# { 'key' => [value, cas_id] }
|
25
|
-
def get_multi_cas(*keys)
|
26
|
-
if block_given?
|
27
|
-
get_multi_yielder(keys) {|*args| yield(*args)}
|
28
|
-
else
|
29
|
-
Hash.new.tap do |hash|
|
30
|
-
get_multi_yielder(keys) {|k, data| hash[k] = data}
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
##
|
36
|
-
# Set the key-value pair, verifying existing CAS.
|
37
|
-
# Returns the resulting CAS value if succeeded, and falsy otherwise.
|
38
|
-
def set_cas(key, value, cas, ttl=nil, options=nil)
|
39
|
-
ttl ||= @options[:expires_in].to_i
|
40
|
-
perform(:set, key, value, ttl, cas, options)
|
41
|
-
end
|
42
|
-
|
43
|
-
##
|
44
|
-
# Conditionally add a key/value pair, verifying existing CAS, only if the
|
45
|
-
# key already exists on the server. Returns the new CAS value if the
|
46
|
-
# operation succeeded, or falsy otherwise.
|
47
|
-
def replace_cas(key, value, cas, ttl=nil, options=nil)
|
48
|
-
ttl ||= @options[:expires_in].to_i
|
49
|
-
perform(:replace, key, value, ttl, cas, options)
|
50
|
-
end
|
51
|
-
|
52
|
-
# Delete a key/value pair, verifying existing CAS.
|
53
|
-
# Returns true if succeeded, and falsy otherwise.
|
54
|
-
def delete_cas(key, cas=0)
|
55
|
-
perform(:delete, key, cas)
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
1
|
+
puts "You can remove `require 'dalli/cas/client'` as this code has been rolled into the standard 'dalli/client'."
|