dalli 2.7.5 → 3.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 29b86664473df52d0ca07fbf21015a39260962a1
4
- data.tar.gz: 5061af271bef6e1db864d5e6de4f9464412e0c67
2
+ SHA256:
3
+ metadata.gz: 3e59130640d863e72dcd5d332f744319e6420066326732b7dff6a9ccfe66fd7b
4
+ data.tar.gz: 9ccd429326d6c4de6e8d8876619943206eb58cefdf78863e4e16e5fe6ebfa86b
5
5
  SHA512:
6
- metadata.gz: 7ccec720347f06a142f74d1a500948390f0dcd3520c73922363267c393d99067cb3682f4c2577cc2cbbd99a18a93f800041eaec7570303c73d5e7ab451b9396e
7
- data.tar.gz: a68483e89e28c82d52852d73c921aa40578abad55a2f3ec9106b01f1fd5dfc6f98104e9b2f8ab0006306685a4b3ecafca3d768ebf81223c213171482ee00d1f1
6
+ metadata.gz: 432e07fbfa6c1d7b5bd10c8c1c665eb9e2455da2eaf71dcd7917dab04d2454fbb756f0a64d599e71a8547fd4215de105f090fe5a79e5f69b3802d441d4b49698
7
+ data.tar.gz: 7bf4a97dbc8ddbfd48aa2fdc82805438d665e335a6b43c50ae96ea55bc2a11b92cb6b65f203981f4c067b3dd67fdd5091a55df591b6e4b154bb4914950baa35a
data/Gemfile CHANGED
@@ -1,5 +1,10 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'kgio', :platform => :mri
5
+ group :test do
6
+ gem "minitest"
7
+ gem "rake"
8
+ gem "simplecov"
9
+ gem "ruby-prof", platform: :mri
10
+ end
data/History.md CHANGED
@@ -1,6 +1,85 @@
1
1
  Dalli Changelog
2
2
  =====================
3
3
 
4
+ 3.0.1
5
+ ==========
6
+
7
+ - Fix syntax error that prevented inclusion of Dalli::Server (ryanfb)
8
+ - Restore with method required by ActiveSupport::Cache::MemCacheStore
9
+
10
+ 3.0.0
11
+ ==========
12
+ - BREAKING CHANGES:
13
+
14
+ - Removes :dalli_store.
15
+ Use Rails' official :mem_cache_store instead.
16
+ https://guides.rubyonrails.org/caching_with_rails.html
17
+ - Attempting to store a larger value than allowed by memcached used to
18
+ print a warning and truncate the value. This now raises an error to
19
+ prevent silent data corruption.
20
+ - Compression now defaults to `true` for large values (greater than 4KB).
21
+ This is intended to minimize errors due to the previous note.
22
+ - Errors marshalling values now raise rather than just printing an error.
23
+ - The Rack session adapter has been refactored to remove support for thread-unsafe
24
+ configurations. You will need to include the `connection_pool` gem in
25
+ your Gemfile to ensure session operations are thread-safe.
26
+
27
+ - Raise NetworkError when multi response gets into corrupt state (mervync, #783)
28
+ - Validate servers argument (semaperepelitsa, petergoldstein, #776)
29
+ - Enable SSL support (bdunne, #775)
30
+ - Add gat operation (tbeauvais, #769)
31
+ - Removes inline native code, use Ruby 2.3+ support for bsearch instead. (mperham)
32
+ - Switch repo to Github Actions and upgrade Ruby versions (petergoldstein, bdunne, Fryguy)
33
+ - Update benchmark test for Rubyprof changes (nateberkopec)
34
+ - Remove support for the `kgio` gem, it is not relevant in Ruby 2.3+. (mperham)
35
+ - Remove inline native code, use Ruby 2.3+ support for bsearch instead. (mperham)
36
+
37
+
38
+ 2.7.11
39
+ ==========
40
+ - DEPRECATION: :dalli_store will be removed in Dalli 3.0.
41
+ Use Rails' official :mem_cache_store instead.
42
+ https://guides.rubyonrails.org/caching_with_rails.html
43
+ - Add new `digest_class` option to Dalli::Client [#724]
44
+ - Don't treat NameError as a network error [#728]
45
+ - Handle nested comma separated server strings (sambostock)
46
+
47
+ 2.7.10
48
+ ==========
49
+ - Revert frozen string change (schneems)
50
+ - Advertise supports_cached_versioning? in DalliStore (schneems)
51
+ - Better detection of fork support, to allow specs to run under Truffle Ruby (deepj)
52
+ - Update logging for over max size to log as error (aeroastro)
53
+
54
+ 2.7.9
55
+ ==========
56
+ - Fix behavior for Rails 5.2+ cache_versioning (GriwMF)
57
+ - Ensure fetch provides the key to the fallback block as an argument (0exp)
58
+ - Assorted performance improvements (schneems)
59
+
60
+ 2.7.8
61
+ ==========
62
+ - Rails 5.2 compatibility (pbougie)
63
+ - Fix Session Cache compatibility (pixeltrix)
64
+
65
+ 2.7.7
66
+ ==========
67
+ - Support large cache keys on fetch multi (sobrinho)
68
+ - Not found checks no longer trigger the result's equality method (dannyfallon)
69
+ - Use SVG build badges (olleolleolle)
70
+ - Travis updates (junaruga, tiarly, petergoldstein)
71
+ - Update default down_retry_delay (jaredhales)
72
+ - Close kgio socket after IO.select timeouts
73
+ - Documentation updates (tipair)
74
+ - Instrument DalliStore errors with instrument_errors configuration option. (btatnall)
75
+
76
+ 2.7.6
77
+ ==========
78
+ - Rails 5.0.0.beta2 compatibility (yui-knk, petergoldstein)
79
+ - Add cas!, a variant of the #cas method that yields to the block whether or not the key already exist (mwpastore)
80
+ - Performance improvements (nateberkopec)
81
+ - Add Ruby 2.3.0 to support matrix (tricknotes)
82
+
4
83
  2.7.5
5
84
  ==========
6
85
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Dalli [![Build Status](https://secure.travis-ci.org/petergoldstein/dalli.png)](http://travis-ci.org/petergoldstein/dalli) [![Dependency Status](https://gemnasium.com/petergoldstein/dalli.png)](https://gemnasium.com/petergoldstein/dalli) [![Code Climate](https://codeclimate.com/github/petergoldstein/dalli.png)](https://codeclimate.com/github/petergoldstein/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,26 +9,6 @@ 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
 
@@ -66,87 +46,29 @@ dc.set('abc', 123)
66
46
  value = dc.get('abc')
67
47
  ```
68
48
 
69
- 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.
70
-
71
- Dalli has no runtime dependencies and never will. You can optionally install the 'kgio' gem to
72
- give Dalli a 20-30% performance boost.
73
-
74
-
75
- Usage with Rails 3.x and 4.x
76
- ---------------------------
77
-
78
- In your Gemfile:
79
-
80
- ```ruby
81
- gem 'dalli'
82
- ```
83
-
84
- In `config/environments/production.rb`:
85
-
86
- ```ruby
87
- config.cache_store = :dalli_store
88
- ```
89
-
90
- 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.
91
-
92
- ```ruby
93
- config.cache_store = :dalli_store, 'cache-1.example.com', 'cache-2.example.com',
94
- { :namespace => NAME_OF_RAILS_APP, :expires_in => 1.day, :compress => true }
95
- ```
96
-
97
- If your servers are specified in `ENV["MEMCACHE_SERVERS"]` (e.g. on Heroku when using a third-party hosted addon), simply provide `nil` for the servers:
98
-
49
+ With SSL enabled:
99
50
  ```ruby
100
- config.cache_store = :dalli_store, nil, { :namespace => NAME_OF_RAILS_APP, :expires_in => 1.day, :compress => true }
101
- ```
102
-
103
- To use Dalli for Rails session storage that times out after 20 minutes, in `config/initializers/session_store.rb`:
104
-
105
- For Rails >= 3.2.4:
106
-
107
- ```ruby
108
- Rails.application.config.session_store ActionDispatch::Session::CacheStore, :expire_after => 20.minutes
109
- ```
110
-
111
- For Rails 3.x:
112
-
113
- ```ruby
114
- require 'action_dispatch/middleware/session/dalli_store'
115
- Rails.application.config.session_store :dalli_store, :memcache_server => ['host1', 'host2'], :namespace => 'sessions', :key => '_foundation_session', :expire_after => 20.minutes
116
- ```
117
-
118
- Dalli does not support Rails 2.x.
119
-
120
-
121
- Multithreading and Rails
122
- --------------------------
123
-
124
- If you use Puma or another threaded app server, as of Dalli 2.7, you can use a pool
125
- of Dalli clients with Rails to ensure the `Rails.cache` singleton does not become a
126
- source of thread contention. You must add `gem 'connection_pool'` to your Gemfile and
127
- add :pool\_size to your `dalli_store` config:
128
-
129
- ```ruby
130
- config.cache_store = :dalli_store, 'cache-1.example.com', { :pool_size => 5 }
51
+ require 'dalli'
52
+ ssl_context = OpenSSL::SSL::SSLContext.new
53
+ ssl_context.ca_file = "./myCA.pem"
54
+ ssl_context.ssl_version = :SSLv23
55
+ ssl_context.verify_hostname = true
56
+ ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
57
+
58
+ dc = Dalli::Client.new("memcached:11212", :ssl_context => ssl_context)
59
+ dc.set("abc", 123)
60
+ value = dc.get("abc")
131
61
  ```
132
62
 
133
- You can then use the Rails cache as normal and Rails.cache will use the pool transparently under the covers, or you can check out a Dalli client directly from the pool:
134
-
135
- ```ruby
136
- Rails.cache.fetch('foo', :expires_in => 300) do
137
- 'bar'
138
- end
139
-
140
- Rails.cache.dalli.with do |client|
141
- # client is a Dalli::Client instance which you can
142
- # use ONLY within this block
143
- end
144
- ```
63
+ 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.
145
64
 
65
+ Dalli has no runtime dependencies.
146
66
 
147
67
  Configuration
148
68
  ------------------------
149
69
 
70
+ **servers**: An Array of "host:port:weight" where weight allows you to distribute cache unevenly.
71
+
150
72
  Dalli::Client accepts the following options. All times are in seconds.
151
73
 
152
74
  **expires_in**: Global default for key TTL. Default is 0, which means no expiry.
@@ -155,7 +77,7 @@ Dalli::Client accepts the following options. All times are in seconds.
155
77
 
156
78
  **failover**: Boolean, if true Dalli will failover to another server if the main server for a key is down. Default is true.
157
79
 
158
- **threadsafe**: Boolean. If true Dalli ensures that only one thread is using a socket at a given time. Default is true. Set to false at your own peril.
80
+ **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.
159
81
 
160
82
  **serializer**: The serializer to use for objects being stored (ex. JSON).
161
83
  Default is Marshal.
@@ -172,16 +94,18 @@ If serving compressed data using nginx's HttpMemcachedModule, set `memcached_gzi
172
94
 
173
95
  **keepalive**: Boolean. If true, Dalli will enable keep-alive for socket connections. Default is true.
174
96
 
175
- **socket_timeout**: Timeout for all socket operations (connect, read, write). Default is 0.5.
97
+ **socket_timeout**: Timeout for all socket operations (connect, read, write). Default is 1.
176
98
 
177
99
  **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.
178
100
 
179
- **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.
101
+ **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.
180
102
 
181
- **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 1 second.
103
+ **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.
182
104
 
183
105
  **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.
184
106
 
107
+ **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.
108
+
185
109
  **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.
186
110
 
187
111
  **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.
@@ -192,10 +116,14 @@ If serving compressed data using nginx's HttpMemcachedModule, set `memcached_gzi
192
116
 
193
117
  **cache_nils**: Boolean. If true Dalli will not treat cached `nil` values as 'not found' for `#fetch` operations. Default is false.
194
118
 
119
+ **raise_errors**: Boolean. When true DalliStore will reraise Dalli:DalliError instead swallowing the error. Default is false.
120
+
121
+ **instrument_errors**: Boolean. When true DalliStore will send notification of Dalli::DalliError via a 'cache_error.active_support' event. Default is false.
122
+
195
123
  Features and Changes
196
124
  ------------------------
197
125
 
198
- By default, Dalli is thread-safe. Disable thread-safety at your own peril.
126
+ By default, Dalli is thread-safe. Disable thread-safety at your own peril.
199
127
 
200
128
  Dalli does not need anything special in Unicorn/Passenger since 2.0.4.
201
129
  It will detect sockets shared with child processes and gracefully reopen the
@@ -208,7 +136,7 @@ Note that Dalli does not require ActiveSupport or Rails. You can safely use it
208
136
  Helping Out
209
137
  -------------
210
138
 
211
- 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.
139
+ 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.
212
140
 
213
141
  We're not accepting new compressors. They are trivial to add in an initializer. See #385 (LZ4), #406 (Snappy)
214
142
 
@@ -1,58 +1 @@
1
- require 'dalli/client'
2
-
3
- module Dalli
4
- class Client
5
- ##
6
- # Get the value and CAS ID associated with the key. If a block is provided,
7
- # value and CAS will be passed to the block.
8
- def get_cas(key)
9
- (value, cas) = perform(:cas, key)
10
- value = (!value || value == 'Not found') ? nil : value
11
- if block_given?
12
- yield value, cas
13
- else
14
- [value, cas]
15
- end
16
- end
17
-
18
- ##
19
- # Fetch multiple keys efficiently, including available metadata such as CAS.
20
- # If a block is given, yields key/data pairs one a time. Data is an array:
21
- # [value, cas_id]
22
- # If no block is given, returns a hash of
23
- # { 'key' => [value, cas_id] }
24
- def get_multi_cas(*keys)
25
- if block_given?
26
- get_multi_yielder(keys) {|*args| yield(*args)}
27
- else
28
- Hash.new.tap do |hash|
29
- get_multi_yielder(keys) {|k, data| hash[k] = data}
30
- end
31
- end
32
- end
33
-
34
- ##
35
- # Set the key-value pair, verifying existing CAS.
36
- # Returns the resulting CAS value if succeeded, and falsy otherwise.
37
- def set_cas(key, value, cas, ttl=nil, options=nil)
38
- ttl ||= @options[:expires_in].to_i
39
- perform(:set, key, value, ttl, cas, options)
40
- end
41
-
42
- ##
43
- # Conditionally add a key/value pair, verifying existing CAS, only if the
44
- # key already exists on the server. Returns the new CAS value if the
45
- # operation succeeded, or falsy otherwise.
46
- def replace_cas(key, value, cas, ttl=nil, options=nil)
47
- ttl ||= @options[:expires_in].to_i
48
- perform(:replace, key, value, ttl, cas, options)
49
- end
50
-
51
- # Delete a key/value pair, verifying existing CAS.
52
- # Returns true if succeeded, and falsy otherwise.
53
- def delete_cas(key, cas=0)
54
- perform(:delete, key, cas)
55
- end
56
-
57
- end
58
- end
1
+ puts "You can remove `require 'dalli/cas/client'` as this code has been rolled into the standard 'dalli/client'."