dalli 2.7.8 → 3.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{History.md → CHANGELOG.md} +168 -0
- data/Gemfile +5 -1
- data/README.md +27 -223
- data/lib/dalli/cas/client.rb +1 -57
- data/lib/dalli/client.rb +227 -254
- data/lib/dalli/compressor.rb +12 -2
- data/lib/dalli/key_manager.rb +121 -0
- data/lib/dalli/options.rb +6 -7
- data/lib/dalli/pipelined_getter.rb +177 -0
- data/lib/dalli/protocol/base.rb +241 -0
- data/lib/dalli/protocol/binary/request_formatter.rb +117 -0
- data/lib/dalli/protocol/binary/response_header.rb +36 -0
- data/lib/dalli/protocol/binary/response_processor.rb +239 -0
- data/lib/dalli/protocol/binary/sasl_authentication.rb +60 -0
- data/lib/dalli/protocol/binary.rb +173 -0
- data/lib/dalli/protocol/connection_manager.rb +252 -0
- data/lib/dalli/protocol/meta/key_regularizer.rb +31 -0
- data/lib/dalli/protocol/meta/request_formatter.rb +121 -0
- data/lib/dalli/protocol/meta/response_processor.rb +211 -0
- data/lib/dalli/protocol/meta.rb +178 -0
- data/lib/dalli/protocol/response_buffer.rb +54 -0
- data/lib/dalli/protocol/server_config_parser.rb +86 -0
- data/lib/dalli/protocol/ttl_sanitizer.rb +45 -0
- data/lib/dalli/protocol/value_compressor.rb +85 -0
- data/lib/dalli/protocol/value_marshaller.rb +59 -0
- data/lib/dalli/protocol/value_serializer.rb +91 -0
- data/lib/dalli/protocol.rb +8 -0
- data/lib/dalli/ring.rb +94 -83
- data/lib/dalli/server.rb +3 -746
- data/lib/dalli/servers_arg_normalizer.rb +54 -0
- data/lib/dalli/socket.rb +117 -137
- data/lib/dalli/version.rb +4 -1
- data/lib/dalli.rb +43 -15
- data/lib/rack/session/dalli.rb +103 -94
- metadata +65 -28
- data/lib/action_dispatch/middleware/session/dalli_store.rb +0 -82
- data/lib/active_support/cache/dalli_store.rb +0 -429
- 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: f0ef39f4ff4e9e465b2522707f3c4eea85a94373ba0d3de4b9d940830001b118
|
4
|
+
data.tar.gz: 35cb362ec6075818f062106769481e92c90752936ecaf9a00fae25725ee4ea94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c6b2b205551fb10fb2e49ab7c3c3eba3c552c0bc4b8132783b51f6cdc7a9ddd4c272bd24ed13f9d78e29353e3b84daec001b2691ad630bdfd517bb7af86fd54
|
7
|
+
data.tar.gz: 6ef9f6733d8e6d5f8a6bf8fb7d782e99c450494e03d4e5fe46037b77665682df63eaa9a3eb05007d1720b175564c8e91524c0df92d0856dc1f68066501732a06
|
data/{History.md → CHANGELOG.md}
RENAMED
@@ -1,6 +1,174 @@
|
|
1
1
|
Dalli Changelog
|
2
2
|
=====================
|
3
3
|
|
4
|
+
Unreleased
|
5
|
+
==========
|
6
|
+
|
7
|
+
3.2.3
|
8
|
+
==========
|
9
|
+
|
10
|
+
- Sanitize CAS inputs to ensure additional commands are not passed to memcached (xhzeem / petergoldstein)
|
11
|
+
- Sanitize input to flush command to ensure additional commands are not passed to memcached (xhzeem / petergoldstein)
|
12
|
+
- Namespaces passed as procs are now evaluated every time, as opposed to just on initialization (nrw505)
|
13
|
+
- Fix missing require of uri in ServerConfigParser (adam12)
|
14
|
+
- Fix link to the CHANGELOG.md file in README.md (rud)
|
15
|
+
|
16
|
+
3.2.2
|
17
|
+
==========
|
18
|
+
|
19
|
+
- Ensure apps are resilient against old session ids (kbrock)
|
20
|
+
|
21
|
+
3.2.1
|
22
|
+
==========
|
23
|
+
|
24
|
+
- Fix null replacement bug on some SASL-authenticated services (veritas1)
|
25
|
+
|
26
|
+
3.2.0
|
27
|
+
==========
|
28
|
+
|
29
|
+
- BREAKING CHANGE: Remove protocol_implementation client option (petergoldstein)
|
30
|
+
- Add protocol option with meta implementation (petergoldstein)
|
31
|
+
|
32
|
+
3.1.6
|
33
|
+
==========
|
34
|
+
|
35
|
+
- Fix bug with cas/cas! with "Not found" value (petergoldstein)
|
36
|
+
- Add Ruby 3.1 to CI (petergoldstein)
|
37
|
+
- Replace reject(&:nil?) with compact (petergoldstein)
|
38
|
+
|
39
|
+
3.1.5
|
40
|
+
==========
|
41
|
+
|
42
|
+
- Fix bug with get_cas key with "Not found" value (petergoldstein)
|
43
|
+
- Replace should return nil, not raise error, on miss (petergoldstein)
|
44
|
+
|
45
|
+
3.1.4
|
46
|
+
==========
|
47
|
+
|
48
|
+
- Improve response parsing performance (casperisfine)
|
49
|
+
- Reorganize binary protocol parsing a bit (petergoldstein)
|
50
|
+
- Fix handling of non-ASCII keys in get_multi (petergoldstein)
|
51
|
+
|
52
|
+
3.1.3
|
53
|
+
==========
|
54
|
+
|
55
|
+
- Restore falsey behavior on delete/delete_cas for nonexistent key (petergoldstein)
|
56
|
+
|
57
|
+
3.1.2
|
58
|
+
==========
|
59
|
+
|
60
|
+
- Make quiet? / multi? public on Dalli::Protocol::Binary (petergoldstein)
|
61
|
+
|
62
|
+
3.1.1
|
63
|
+
==========
|
64
|
+
|
65
|
+
- Add quiet support for incr, decr, append, depend, and flush (petergoldstein)
|
66
|
+
- Additional refactoring to allow reuse of connection behavior (petergoldstein)
|
67
|
+
- Fix issue in flush such that it wasn't passing the delay argument to memcached (petergoldstein)
|
68
|
+
|
69
|
+
3.1.0
|
70
|
+
==========
|
71
|
+
|
72
|
+
- BREAKING CHANGE: Update Rack::Session::Dalli to inherit from Abstract::PersistedSecure. This will invalidate existing sessions (petergoldstein)
|
73
|
+
- BREAKING CHANGE: Use of unsupported operations in a multi block now raise an error. (petergoldstein)
|
74
|
+
- Extract PipelinedGetter from Dalli::Client (petergoldstein)
|
75
|
+
- Fix SSL socket so that it works with pipelined gets (petergoldstein)
|
76
|
+
- Additional refactoring to split classes (petergoldstein)
|
77
|
+
|
78
|
+
3.0.6
|
79
|
+
==========
|
80
|
+
|
81
|
+
- Fix regression in SASL authentication response parsing (petergoldstein)
|
82
|
+
|
83
|
+
3.0.5
|
84
|
+
==========
|
85
|
+
|
86
|
+
- Add Rubocop and fix most outstanding issues (petergoldstein)
|
87
|
+
- Extract a number of classes, to simplify the largest classes (petergoldstein)
|
88
|
+
- Ensure against socket corruption if an error occurs in a multi block (petergoldstein)
|
89
|
+
|
90
|
+
3.0.4
|
91
|
+
==========
|
92
|
+
|
93
|
+
- Clean connections and retry after NetworkError in get_multi (andrejbl)
|
94
|
+
- Internal refactoring and cleanup (petergoldstein)
|
95
|
+
|
96
|
+
3.0.3
|
97
|
+
==========
|
98
|
+
|
99
|
+
- Restore ability for `compress` to be disabled on a per request basis (petergoldstein)
|
100
|
+
- Fix broken image in README (deining)
|
101
|
+
- Use bundler-cache in CI (olleolleolle)
|
102
|
+
- Remove the OpenSSL extensions dependency (petergoldstein)
|
103
|
+
- Add Memcached 1.5.x to the CI matrix
|
104
|
+
- Updated compression documentation (petergoldstein)
|
105
|
+
|
106
|
+
3.0.2
|
107
|
+
==========
|
108
|
+
|
109
|
+
- Restore Windows compatibility (petergoldstein)
|
110
|
+
- Add JRuby to CI and make requisite changes (petergoldstein)
|
111
|
+
- Clarify documentation for supported rubies (petergoldstein)
|
112
|
+
|
113
|
+
3.0.1
|
114
|
+
==========
|
115
|
+
|
116
|
+
- Fix syntax error that prevented inclusion of Dalli::Server (ryanfb)
|
117
|
+
- Restore with method required by ActiveSupport::Cache::MemCacheStore
|
118
|
+
|
119
|
+
3.0.0
|
120
|
+
==========
|
121
|
+
- BREAKING CHANGES:
|
122
|
+
|
123
|
+
* Removes :dalli_store.
|
124
|
+
Use Rails' official :mem_cache_store instead.
|
125
|
+
https://guides.rubyonrails.org/caching_with_rails.html
|
126
|
+
* Attempting to store a larger value than allowed by memcached used to
|
127
|
+
print a warning and truncate the value. This now raises an error to
|
128
|
+
prevent silent data corruption.
|
129
|
+
* Compression now defaults to `true` for large values (greater than 4KB).
|
130
|
+
This is intended to minimize errors due to the previous note.
|
131
|
+
* Errors marshalling values now raise rather than just printing an error.
|
132
|
+
* The Rack session adapter has been refactored to remove support for thread-unsafe
|
133
|
+
configurations. You will need to include the `connection_pool` gem in
|
134
|
+
your Gemfile to ensure session operations are thread-safe.
|
135
|
+
* When using namespaces, the algorithm for calculating truncated keys was
|
136
|
+
changed. Non-truncated keys and truncated keys for the non-namespace
|
137
|
+
case were left unchanged.
|
138
|
+
|
139
|
+
- Raise NetworkError when multi response gets into corrupt state (mervync, #783)
|
140
|
+
- Validate servers argument (semaperepelitsa, petergoldstein, #776)
|
141
|
+
- Enable SSL support (bdunne, #775)
|
142
|
+
- Add gat operation (tbeauvais, #769)
|
143
|
+
- Removes inline native code, use Ruby 2.3+ support for bsearch instead. (mperham)
|
144
|
+
- Switch repo to Github Actions and upgrade Ruby versions (petergoldstein, bdunne, Fryguy)
|
145
|
+
- Update benchmark test for Rubyprof changes (nateberkopec)
|
146
|
+
- Remove support for the `kgio` gem, it is not relevant in Ruby 2.3+. (mperham)
|
147
|
+
- Remove inline native code, use Ruby 2.3+ support for bsearch instead. (mperham)
|
148
|
+
|
149
|
+
|
150
|
+
2.7.11
|
151
|
+
==========
|
152
|
+
- DEPRECATION: :dalli_store will be removed in Dalli 3.0.
|
153
|
+
Use Rails' official :mem_cache_store instead.
|
154
|
+
https://guides.rubyonrails.org/caching_with_rails.html
|
155
|
+
- Add new `digest_class` option to Dalli::Client [#724]
|
156
|
+
- Don't treat NameError as a network error [#728]
|
157
|
+
- Handle nested comma separated server strings (sambostock)
|
158
|
+
|
159
|
+
2.7.10
|
160
|
+
==========
|
161
|
+
- Revert frozen string change (schneems)
|
162
|
+
- Advertise supports_cached_versioning? in DalliStore (schneems)
|
163
|
+
- Better detection of fork support, to allow specs to run under Truffle Ruby (deepj)
|
164
|
+
- Update logging for over max size to log as error (aeroastro)
|
165
|
+
|
166
|
+
2.7.9
|
167
|
+
==========
|
168
|
+
- Fix behavior for Rails 5.2+ cache_versioning (GriwMF)
|
169
|
+
- Ensure fetch provides the key to the fallback block as an argument (0exp)
|
170
|
+
- Assorted performance improvements (schneems)
|
171
|
+
|
4
172
|
2.7.8
|
5
173
|
==========
|
6
174
|
- Rails 5.2 compatibility (pbougie)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,246 +1,50 @@
|
|
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
|
-
Dalli is a high performance pure Ruby client for accessing memcached servers.
|
4
|
+
Dalli is a high performance pure Ruby client for accessing memcached servers.
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
![Persistence of Memory](http://www.virtualdali.com/assets/paintings/31PersistenceOfMemory.jpg)
|
9
|
-
|
10
|
-
Dalli's initial development was sponsored by [CouchBase](http://www.couchbase.com/). Many thanks to them!
|
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
|
-
Supported Ruby versions and implementations
|
33
|
-
------------------------------------------------
|
34
|
-
|
35
|
-
Dalli should work identically on:
|
36
|
-
|
37
|
-
* JRuby 1.6+
|
38
|
-
* Ruby 1.9.3+
|
39
|
-
* Rubinius 2.0
|
40
|
-
|
41
|
-
If you have problems, please enter an issue.
|
42
|
-
|
43
|
-
|
44
|
-
Installation and Usage
|
45
|
-
------------------------
|
46
|
-
|
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 1.4.x using Homebrew with
|
48
|
-
|
49
|
-
brew install memcached
|
50
|
-
|
51
|
-
On Ubuntu you can install it by running:
|
52
|
-
|
53
|
-
apt-get install memcached
|
54
|
-
|
55
|
-
You can verify your installation using this piece of code:
|
56
|
-
|
57
|
-
```bash
|
58
|
-
gem install dalli
|
59
|
-
```
|
60
|
-
|
61
|
-
```ruby
|
62
|
-
require 'dalli'
|
63
|
-
options = { :namespace => "app_v1", :compress => true }
|
64
|
-
dc = Dalli::Client.new('localhost:11211', options)
|
65
|
-
dc.set('abc', 123)
|
66
|
-
value = dc.get('abc')
|
67
|
-
```
|
68
|
-
|
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:11211:2',
|
94
|
-
{ :namespace => NAME_OF_RAILS_APP, :expires_in => 1.day, :compress => true }
|
95
|
-
```
|
96
|
-
|
97
|
-
You can specify a port and a weight by appending to the server name. You may wish to increase the weight of a server with more memory configured. (e.g. to specify port 11211 and a weight of 2, append `:11211:2` )
|
98
|
-
|
99
|
-
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:
|
100
|
-
|
101
|
-
```ruby
|
102
|
-
config.cache_store = :dalli_store, nil, { :namespace => NAME_OF_RAILS_APP, :expires_in => 1.day, :compress => true }
|
103
|
-
```
|
104
|
-
|
105
|
-
To use Dalli for Rails session storage that times out after 20 minutes, in `config/initializers/session_store.rb`:
|
106
|
-
|
107
|
-
For Rails >= 3.2.4:
|
108
|
-
|
109
|
-
```ruby
|
110
|
-
Rails.application.config.session_store ActionDispatch::Session::CacheStore, :expire_after => 20.minutes
|
111
|
-
```
|
6
|
+
Dalli supports:
|
112
7
|
|
113
|
-
|
8
|
+
* Simple and complex memcached configurations
|
9
|
+
* Failover between memcached instances
|
10
|
+
* Fine-grained control of data serialization and compression
|
11
|
+
* Thread-safe operation (either through use of a connection pool, or by using the Dalli client in threadsafe mode)
|
12
|
+
* SSL/TLS connections to memcached
|
13
|
+
* SASL authentication
|
114
14
|
|
115
|
-
|
116
|
-
require 'action_dispatch/middleware/session/dalli_store'
|
117
|
-
Rails.application.config.session_store :dalli_store, :memcache_server => ['host1', 'host2'], :namespace => 'sessions', :key => '_foundation_session', :expire_after => 20.minutes
|
118
|
-
```
|
119
|
-
|
120
|
-
Dalli does not support Rails 2.x.
|
121
|
-
|
122
|
-
|
123
|
-
Multithreading and Rails
|
124
|
-
--------------------------
|
125
|
-
|
126
|
-
If you use Puma or another threaded app server, as of Dalli 2.7, you can use a pool
|
127
|
-
of Dalli clients with Rails to ensure the `Rails.cache` singleton does not become a
|
128
|
-
source of thread contention. You must add `gem 'connection_pool'` to your Gemfile and
|
129
|
-
add :pool\_size to your `dalli_store` config:
|
130
|
-
|
131
|
-
```ruby
|
132
|
-
config.cache_store = :dalli_store, 'cache-1.example.com', { :pool_size => 5 }
|
133
|
-
```
|
134
|
-
|
135
|
-
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:
|
136
|
-
|
137
|
-
```ruby
|
138
|
-
Rails.cache.fetch('foo', :expires_in => 300) do
|
139
|
-
'bar'
|
140
|
-
end
|
141
|
-
|
142
|
-
Rails.cache.dalli.with do |client|
|
143
|
-
# client is a Dalli::Client instance which you can
|
144
|
-
# use ONLY within this block
|
145
|
-
end
|
146
|
-
```
|
147
|
-
|
148
|
-
|
149
|
-
Configuration
|
150
|
-
------------------------
|
151
|
-
|
152
|
-
**servers**: An Array of "host:port:weight" where weight allows you to distribute cache unevenly.
|
153
|
-
|
154
|
-
Dalli::Client accepts the following options. All times are in seconds.
|
155
|
-
|
156
|
-
**expires_in**: Global default for key TTL. Default is 0, which means no expiry.
|
157
|
-
|
158
|
-
**namespace**: If specified, prepends each key with this value to provide simple namespacing. Default is nil.
|
159
|
-
|
160
|
-
**failover**: Boolean, if true Dalli will failover to another server if the main server for a key is down. Default is true.
|
161
|
-
|
162
|
-
**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.
|
163
|
-
|
164
|
-
**serializer**: The serializer to use for objects being stored (ex. JSON).
|
165
|
-
Default is Marshal.
|
166
|
-
|
167
|
-
**compress**: Boolean, if true Dalli will gzip-compress values larger than 1K. Default is false.
|
168
|
-
|
169
|
-
**compression_min_size**: Minimum value byte size for which to attempt compression. Default is 1K.
|
170
|
-
|
171
|
-
**compression_max_size**: Maximum value byte size for which to attempt compression. Default is unlimited.
|
172
|
-
|
173
|
-
**compressor**: The compressor to use for objects being stored.
|
174
|
-
Default is zlib, implemented under `Dalli::Compressor`.
|
175
|
-
If serving compressed data using nginx's HttpMemcachedModule, set `memcached_gzip_flag 2` and use `Dalli::GzipCompressor`
|
176
|
-
|
177
|
-
**keepalive**: Boolean. If true, Dalli will enable keep-alive for socket connections. Default is true.
|
178
|
-
|
179
|
-
**socket_timeout**: Timeout for all socket operations (connect, read, write). Default is 0.5.
|
180
|
-
|
181
|
-
**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.
|
182
|
-
|
183
|
-
**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.
|
184
|
-
|
185
|
-
**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 60 seconds.
|
186
|
-
|
187
|
-
**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.
|
188
|
-
|
189
|
-
**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.
|
190
|
-
|
191
|
-
**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.
|
192
|
-
|
193
|
-
**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.
|
194
|
-
|
195
|
-
**sndbuf**: In bytes, set the socket SO_SNDBUF. Defaults to operating system default.
|
196
|
-
|
197
|
-
**rcvbuf**: In bytes, set the socket SO_RCVBUF. Defaults to operating system default.
|
198
|
-
|
199
|
-
**cache_nils**: Boolean. If true Dalli will not treat cached `nil` values as 'not found' for `#fetch` operations. Default is false.
|
200
|
-
|
201
|
-
**raise_errors**: Boolean. When true DalliStore will reraise Dalli:DalliError instead swallowing the error. Default is false.
|
202
|
-
|
203
|
-
**instrument_errors**: Boolean. When true DalliStore will send notification of Dalli::DalliError via a 'cache_error.active_support' event. Default is false.
|
204
|
-
|
205
|
-
Features and Changes
|
206
|
-
------------------------
|
207
|
-
|
208
|
-
By default, Dalli is thread-safe. Disable thread-safety at your own peril.
|
209
|
-
|
210
|
-
Dalli does not need anything special in Unicorn/Passenger since 2.0.4.
|
211
|
-
It will detect sockets shared with child processes and gracefully reopen the
|
212
|
-
socket.
|
15
|
+
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).
|
213
16
|
|
214
|
-
|
17
|
+
![Persistence of Memory](https://upload.wikimedia.org/wikipedia/en/d/dd/The_Persistence_of_Memory.jpg)
|
215
18
|
|
216
|
-
[View the Client API](http://www.rubydoc.info/github/mperham/dalli/Dalli/Client)
|
217
19
|
|
218
|
-
|
219
|
-
-------------
|
20
|
+
## Documentation and Information
|
220
21
|
|
221
|
-
|
22
|
+
* [User Documentation](https://github.com/petergoldstein/dalli/wiki) - The documentation is maintained in the repository's wiki.
|
23
|
+
* [Announcements](https://github.com/petergoldstein/dalli/discussions/categories/announcements) - Announcements of interest to the Dalli community will be posted here.
|
24
|
+
* [Bug Reports](https://github.com/petergoldstein/dalli/issues) - If you discover a problem with Dalli, please submit a bug report in the tracker.
|
25
|
+
* [Forum](https://github.com/petergoldstein/dalli/discussions/categories/q-a) - If you have questions about Dalli, please post them here.
|
26
|
+
* [Client API](https://rubydoc.info/github/petergoldstein/dalli/Dalli/Client) - Ruby documentation for the `Dalli::Client` API
|
222
27
|
|
223
|
-
|
28
|
+
## Contributing
|
224
29
|
|
225
|
-
|
226
|
-
------------
|
30
|
+
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 the [changelog](CHANGELOG.md) with a one sentence description of your fix so you get credit as a contributor.
|
227
31
|
|
228
|
-
|
32
|
+
## Appreciation
|
229
33
|
|
230
|
-
|
34
|
+
Dalli would not exist in its current form without the contributions of many people. But special thanks go to several individuals and organizations:
|
231
35
|
|
232
|
-
|
36
|
+
* Mike Perham - for originally authoring the Dalli project and serving as maintainer and primary contributor for many years
|
37
|
+
* Eric Wong - for help using his [kgio](http://bogomips.org/kgio/) library.
|
38
|
+
* Brian Mitchell - for his remix-stash project which was helpful when implementing and testing the binary protocol support.
|
39
|
+
* [CouchBase](http://couchbase.com) - for their sponsorship of the original development
|
233
40
|
|
234
|
-
[CouchBase](http://couchbase.com) - for their project sponsorship
|
235
41
|
|
236
|
-
Authors
|
237
|
-
----------
|
42
|
+
## Authors
|
238
43
|
|
239
44
|
* [Peter M. Goldstein](https://github.com/petergoldstein) - current maintainer
|
240
45
|
* [Mike Perham](https://github.com/mperham) and contributors
|
241
46
|
|
242
47
|
|
243
|
-
Copyright
|
244
|
-
-----------
|
48
|
+
## Copyright
|
245
49
|
|
246
50
|
Copyright (c) Mike Perham, Peter M. Goldstein. See LICENSE for details.
|
data/lib/dalli/cas/client.rb
CHANGED
@@ -1,59 +1,3 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'dalli/client'
|
3
2
|
|
4
|
-
|
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
|
3
|
+
puts "You can remove `require 'dalli/cas/client'` as this code has been rolled into the standard 'dalli/client'."
|