dalli 2.7.11 → 3.0.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.
- checksums.yaml +4 -4
- data/Gemfile +5 -10
- data/History.md +57 -0
- data/README.md +26 -91
- data/lib/dalli/cas/client.rb +1 -59
- data/lib/dalli/client.rb +183 -110
- data/lib/dalli/compressor.rb +4 -3
- data/lib/dalli/options.rb +3 -4
- data/lib/dalli/protocol/binary.rb +703 -0
- data/lib/dalli/protocol/server_config_parser.rb +67 -0
- data/lib/dalli/protocol/ttl_sanitizer.rb +45 -0
- data/lib/dalli/protocol/value_compressor.rb +85 -0
- data/lib/dalli/protocol.rb +9 -0
- data/lib/dalli/ring.rb +12 -63
- data/lib/dalli/server.rb +2 -748
- data/lib/dalli/socket.rb +62 -128
- data/lib/dalli/version.rb +2 -1
- data/lib/dalli.rb +17 -16
- data/lib/rack/session/dalli.rb +21 -40
- metadata +37 -8
- data/lib/action_dispatch/middleware/session/dalli_store.rb +0 -82
- data/lib/active_support/cache/dalli_store.rb +0 -441
- 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: de12f6f4e7e074752c4b3d2ccaa24450fd081e6e4ded890c632158858e5aa939
|
4
|
+
data.tar.gz: '01093957dc00b0742995b5d9198014dc480bd08788f4f3c2e5160cd2a6ca8725'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c073d5ce9922b8617c11c507b8b90603ccdf304419c2fe395af33467f880c75e4a22e9e5e6eae387c78ae937b6b8de5d68eba87b323967cce03a8aaffeeba1d8
|
7
|
+
data.tar.gz: f7fd88ee88a887c44a1b94d0e3c6c7b0d210d08c38db39ea387585a18a82c5cd0a4e9a57daaa444e927e4c47f81fbd404daeec139ded6d8ff6d39fe3e565022d
|
data/Gemfile
CHANGED
@@ -1,15 +1,10 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'appraisal'
|
6
|
-
gem 'kgio', :platform => :mri
|
7
|
-
gem 'rails'
|
8
|
-
|
9
5
|
group :test do
|
10
|
-
gem
|
11
|
-
gem
|
12
|
-
gem
|
13
|
-
gem
|
14
|
-
gem 'simplecov'
|
6
|
+
gem "minitest"
|
7
|
+
gem "rake"
|
8
|
+
gem "simplecov"
|
9
|
+
gem "ruby-prof", platform: :mri
|
15
10
|
end
|
data/History.md
CHANGED
@@ -1,6 +1,63 @@
|
|
1
1
|
Dalli Changelog
|
2
2
|
=====================
|
3
3
|
|
4
|
+
3.0.4
|
5
|
+
==========
|
6
|
+
|
7
|
+
- Clean connections and retry after NetworkError in get_multi (andrejbl)
|
8
|
+
- Internal refactoring and cleanup (petergoldstein)
|
9
|
+
|
10
|
+
3.0.3
|
11
|
+
==========
|
12
|
+
|
13
|
+
- Restore ability for `compress` to be disabled on a per request basis (petergoldstein)
|
14
|
+
- Fix broken image in README (deining)
|
15
|
+
- Use bundler-cache in CI (olleolleolle)
|
16
|
+
- Remove the OpenSSL extensions dependency (petergoldstein)
|
17
|
+
- Add Memcached 1.5.x to the CI matrix
|
18
|
+
- Updated compression documentation (petergoldstein)
|
19
|
+
|
20
|
+
3.0.2
|
21
|
+
==========
|
22
|
+
|
23
|
+
- Restore Windows compatibility (petergoldstein)
|
24
|
+
- Add JRuby to CI and make requisite changes (petergoldstein)
|
25
|
+
- Clarify documentation for supported rubies (petergoldstein)
|
26
|
+
|
27
|
+
3.0.1
|
28
|
+
==========
|
29
|
+
|
30
|
+
- Fix syntax error that prevented inclusion of Dalli::Server (ryanfb)
|
31
|
+
- Restore with method required by ActiveSupport::Cache::MemCacheStore
|
32
|
+
|
33
|
+
3.0.0
|
34
|
+
==========
|
35
|
+
- BREAKING CHANGES:
|
36
|
+
|
37
|
+
* Removes :dalli_store.
|
38
|
+
Use Rails' official :mem_cache_store instead.
|
39
|
+
https://guides.rubyonrails.org/caching_with_rails.html
|
40
|
+
* Attempting to store a larger value than allowed by memcached used to
|
41
|
+
print a warning and truncate the value. This now raises an error to
|
42
|
+
prevent silent data corruption.
|
43
|
+
* Compression now defaults to `true` for large values (greater than 4KB).
|
44
|
+
This is intended to minimize errors due to the previous note.
|
45
|
+
* Errors marshalling values now raise rather than just printing an error.
|
46
|
+
* The Rack session adapter has been refactored to remove support for thread-unsafe
|
47
|
+
configurations. You will need to include the `connection_pool` gem in
|
48
|
+
your Gemfile to ensure session operations are thread-safe.
|
49
|
+
|
50
|
+
- Raise NetworkError when multi response gets into corrupt state (mervync, #783)
|
51
|
+
- Validate servers argument (semaperepelitsa, petergoldstein, #776)
|
52
|
+
- Enable SSL support (bdunne, #775)
|
53
|
+
- Add gat operation (tbeauvais, #769)
|
54
|
+
- Removes inline native code, use Ruby 2.3+ support for bsearch instead. (mperham)
|
55
|
+
- Switch repo to Github Actions and upgrade Ruby versions (petergoldstein, bdunne, Fryguy)
|
56
|
+
- Update benchmark test for Rubyprof changes (nateberkopec)
|
57
|
+
- Remove support for the `kgio` gem, it is not relevant in Ruby 2.3+. (mperham)
|
58
|
+
- Remove inline native code, use Ruby 2.3+ support for bsearch instead. (mperham)
|
59
|
+
|
60
|
+
|
4
61
|
2.7.11
|
5
62
|
==========
|
6
63
|
- DEPRECATION: :dalli_store will be removed in Dalli 3.0.
|
data/README.md
CHANGED
@@ -1,22 +1,21 @@
|
|
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.
|
5
5
|
|
6
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
7
|
|
8
|
-
![Persistence of Memory](
|
8
|
+
![Persistence of Memory](https://upload.wikimedia.org/wikipedia/en/d/dd/The_Persistence_of_Memory.jpg)
|
9
9
|
|
10
10
|
Dalli's initial development was sponsored by [CouchBase](http://www.couchbase.com/). Many thanks to them!
|
11
11
|
|
12
12
|
Supported Ruby versions and implementations
|
13
13
|
------------------------------------------------
|
14
14
|
|
15
|
-
Dalli
|
15
|
+
As of Dalli version 3.0 the following Ruby versions are supported:
|
16
16
|
|
17
|
-
*
|
18
|
-
*
|
19
|
-
* 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
|
20
19
|
|
21
20
|
If you have problems, please enter an issue.
|
22
21
|
|
@@ -24,7 +23,7 @@ If you have problems, please enter an issue.
|
|
24
23
|
Installation and Usage
|
25
24
|
------------------------
|
26
25
|
|
27
|
-
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
|
28
27
|
|
29
28
|
brew install memcached
|
30
29
|
|
@@ -40,89 +39,29 @@ gem install dalli
|
|
40
39
|
|
41
40
|
```ruby
|
42
41
|
require 'dalli'
|
43
|
-
options = { :
|
42
|
+
options = { namespace: "app_v1", compress: true }
|
44
43
|
dc = Dalli::Client.new('localhost:11211', options)
|
45
44
|
dc.set('abc', 123)
|
46
45
|
value = dc.get('abc')
|
47
46
|
```
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
Dalli has no runtime dependencies.
|
52
|
-
|
53
|
-
Usage with Rails 3.x and 4.x
|
54
|
-
---------------------------
|
55
|
-
|
56
|
-
In your Gemfile:
|
57
|
-
|
58
|
-
```ruby
|
59
|
-
gem 'dalli'
|
60
|
-
```
|
61
|
-
|
62
|
-
In `config/environments/production.rb`:
|
63
|
-
|
64
|
-
```ruby
|
65
|
-
config.cache_store = :dalli_store
|
66
|
-
```
|
67
|
-
|
68
|
-
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.
|
69
|
-
|
48
|
+
With SSL enabled:
|
70
49
|
```ruby
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
```
|
82
|
-
|
83
|
-
To use Dalli for Rails session storage that times out after 20 minutes, in `config/initializers/session_store.rb`:
|
84
|
-
|
85
|
-
For Rails >= 3.2.4:
|
86
|
-
|
87
|
-
```ruby
|
88
|
-
Rails.application.config.session_store ActionDispatch::Session::CacheStore, :expire_after => 20.minutes
|
89
|
-
```
|
90
|
-
|
91
|
-
For Rails 3.x:
|
92
|
-
|
93
|
-
```ruby
|
94
|
-
require 'action_dispatch/middleware/session/dalli_store'
|
95
|
-
Rails.application.config.session_store :dalli_store, :memcache_server => ['host1', 'host2'], :namespace => 'sessions', :key => '_foundation_session', :expire_after => 20.minutes
|
96
|
-
```
|
97
|
-
|
98
|
-
Dalli does not support Rails 2.x.
|
99
|
-
|
100
|
-
|
101
|
-
Multithreading and Rails
|
102
|
-
--------------------------
|
103
|
-
|
104
|
-
If you use Puma or another threaded app server, as of Dalli 2.7, you can use a pool
|
105
|
-
of Dalli clients with Rails to ensure the `Rails.cache` singleton does not become a
|
106
|
-
source of thread contention. You must add `gem 'connection_pool'` to your Gemfile and
|
107
|
-
add :pool\_size to your `dalli_store` config:
|
108
|
-
|
109
|
-
```ruby
|
110
|
-
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")
|
111
60
|
```
|
112
61
|
|
113
|
-
|
114
|
-
|
115
|
-
```ruby
|
116
|
-
Rails.cache.fetch('foo', :expires_in => 300) do
|
117
|
-
'bar'
|
118
|
-
end
|
119
|
-
|
120
|
-
Rails.cache.dalli.with do |client|
|
121
|
-
# client is a Dalli::Client instance which you can
|
122
|
-
# use ONLY within this block
|
123
|
-
end
|
124
|
-
```
|
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.
|
125
63
|
|
64
|
+
Dalli has no runtime dependencies.
|
126
65
|
|
127
66
|
Configuration
|
128
67
|
------------------------
|
@@ -142,11 +81,9 @@ Dalli::Client accepts the following options. All times are in seconds.
|
|
142
81
|
**serializer**: The serializer to use for objects being stored (ex. JSON).
|
143
82
|
Default is Marshal.
|
144
83
|
|
145
|
-
**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. Can be overridden on a per-request basis. Default is true.
|
146
85
|
|
147
|
-
**compression_min_size**: Minimum value byte size for which to attempt compression. Default is
|
148
|
-
|
149
|
-
**compression_max_size**: Maximum value byte size for which to attempt compression. Default is unlimited.
|
86
|
+
**compression_min_size**: Minimum value byte size for which to attempt compression. Default is 4K.
|
150
87
|
|
151
88
|
**compressor**: The compressor to use for objects being stored.
|
152
89
|
Default is zlib, implemented under `Dalli::Compressor`.
|
@@ -154,18 +91,16 @@ If serving compressed data using nginx's HttpMemcachedModule, set `memcached_gzi
|
|
154
91
|
|
155
92
|
**keepalive**: Boolean. If true, Dalli will enable keep-alive for socket connections. Default is true.
|
156
93
|
|
157
|
-
**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.
|
158
95
|
|
159
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.
|
160
97
|
|
161
|
-
**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.
|
162
99
|
|
163
|
-
**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.
|
164
101
|
|
165
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.
|
166
103
|
|
167
|
-
**error_when_over_max_size**: Boolean. If true, Dalli will throw a Dalli::ValueOverMaxSize exception when trying to store data larger than **value_max_bytes**. Defaults to false, meaning only a warning is logged.
|
168
|
-
|
169
104
|
**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.
|
170
105
|
|
171
106
|
**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.
|
@@ -198,7 +133,7 @@ Helping Out
|
|
198
133
|
|
199
134
|
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.
|
200
135
|
|
201
|
-
We're not accepting new compressors. They are trivial to add in an initializer. See #385 (LZ4), #406 (Snappy)
|
136
|
+
We're not accepting new compressors. They are trivial to add in an initializer. See [#385](https://github.com/petergoldstein/dalli/pull/385) (LZ4), [#406](https://github.com/petergoldstein/dalli/pull/406) (Snappy)
|
202
137
|
|
203
138
|
Thanks
|
204
139
|
------------
|
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'."
|