dalli 2.0.1 → 3.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +671 -0
  3. data/Gemfile +15 -3
  4. data/LICENSE +1 -1
  5. data/README.md +33 -148
  6. data/lib/dalli/cas/client.rb +3 -0
  7. data/lib/dalli/client.rb +293 -131
  8. data/lib/dalli/compressor.rb +40 -0
  9. data/lib/dalli/key_manager.rb +121 -0
  10. data/lib/dalli/options.rb +22 -4
  11. data/lib/dalli/pid_cache.rb +40 -0
  12. data/lib/dalli/pipelined_getter.rb +177 -0
  13. data/lib/dalli/protocol/base.rb +250 -0
  14. data/lib/dalli/protocol/binary/request_formatter.rb +117 -0
  15. data/lib/dalli/protocol/binary/response_header.rb +36 -0
  16. data/lib/dalli/protocol/binary/response_processor.rb +239 -0
  17. data/lib/dalli/protocol/binary/sasl_authentication.rb +60 -0
  18. data/lib/dalli/protocol/binary.rb +173 -0
  19. data/lib/dalli/protocol/connection_manager.rb +255 -0
  20. data/lib/dalli/protocol/meta/key_regularizer.rb +31 -0
  21. data/lib/dalli/protocol/meta/request_formatter.rb +121 -0
  22. data/lib/dalli/protocol/meta/response_processor.rb +211 -0
  23. data/lib/dalli/protocol/meta.rb +178 -0
  24. data/lib/dalli/protocol/response_buffer.rb +54 -0
  25. data/lib/dalli/protocol/server_config_parser.rb +86 -0
  26. data/lib/dalli/protocol/ttl_sanitizer.rb +45 -0
  27. data/lib/dalli/protocol/value_compressor.rb +85 -0
  28. data/lib/dalli/protocol/value_marshaller.rb +59 -0
  29. data/lib/dalli/protocol/value_serializer.rb +91 -0
  30. data/lib/dalli/protocol.rb +19 -0
  31. data/lib/dalli/ring.rb +98 -50
  32. data/lib/dalli/server.rb +4 -524
  33. data/lib/dalli/servers_arg_normalizer.rb +54 -0
  34. data/lib/dalli/socket.rb +154 -53
  35. data/lib/dalli/version.rb +5 -1
  36. data/lib/dalli.rb +49 -13
  37. data/lib/rack/session/dalli.rb +169 -26
  38. metadata +53 -88
  39. data/History.md +0 -262
  40. data/Performance.md +0 -42
  41. data/Rakefile +0 -39
  42. data/dalli.gemspec +0 -28
  43. data/lib/action_dispatch/middleware/session/dalli_store.rb +0 -76
  44. data/lib/active_support/cache/dalli_store.rb +0 -203
  45. data/test/abstract_unit.rb +0 -281
  46. data/test/benchmark_test.rb +0 -187
  47. data/test/helper.rb +0 -41
  48. data/test/memcached_mock.rb +0 -113
  49. data/test/test_active_support.rb +0 -163
  50. data/test/test_dalli.rb +0 -461
  51. data/test/test_encoding.rb +0 -43
  52. data/test/test_failover.rb +0 -107
  53. data/test/test_network.rb +0 -54
  54. data/test/test_ring.rb +0 -85
  55. data/test/test_sasl.rb +0 -83
  56. data/test/test_session_store.rb +0 -224
data/README.md CHANGED
@@ -1,171 +1,56 @@
1
- Dalli [![Build Status](https://secure.travis-ci.org/mperham/dalli.png)](http://travis-ci.org/mperham/dalli) [![Dependency Status](https://gemnasium.com/mperham/dalli.png)](https://gemnasium.com/mperham/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. 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.
4
+ Dalli is a high performance pure Ruby client for accessing memcached servers.
5
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 initial development was sponsored by [CouchBase](http://www.couchbase.com/). Many thanks to them!
11
-
12
-
13
- Design
14
- ------------
15
-
16
- I 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.2+
39
- * Ruby 1.8.7+
40
- * Rubinius 2.0
41
-
42
- If you have problems, please enter an issue.
43
-
44
-
45
- Installation and Usage
46
- ------------------------
47
-
48
- Remember, Dalli **requires** memcached 1.4+. You can check the version with `memcached -h`. Please note that memcached that Mac OS X Snow Leopard ships with is 1.2.8 and won't work. Install 1.4.x using Homebrew with
49
-
50
- brew install memcached
51
-
52
-
53
- You can verify your installation using this piece of code:
54
-
55
- gem install dalli
56
-
57
- require 'dalli'
58
- dc = Dalli::Client.new('localhost:11211')
59
- dc.set('abc', 123)
60
- value = dc.get('abc')
61
-
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.
63
-
64
- Dalli has no runtime dependencies and never will. You can optionally install the 'kgio' gem to
65
- give Dalli a 20-30% performance boost.
66
-
67
-
68
- Usage with Rails 3.x
69
- ---------------------------
6
+ Dalli supports:
70
7
 
71
- In your Gemfile:
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
72
14
 
73
- gem 'dalli'
74
-
75
- In `config/environments/production.rb`:
76
-
77
- config.cache_store = :dalli_store
78
-
79
- 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.
80
-
81
- config.cache_store = :dalli_store, 'cache-1.example.com', 'cache-2.example.com',
82
- { :namespace => NAME_OF_RAILS_APP, :expires_in => 1.day, :compress => true }
83
-
84
- To use Dalli for Rails session storage, in `config/initializers/session_store.rb`:
85
-
86
- require 'action_dispatch/middleware/session/dalli_store'
87
- Rails.application.config.session_store :dalli_store, :memcache_server => ['host1', 'host2'], :namespace => 'sessions', :key => '_foundation_session', :expire_after => 30.minutes
88
-
89
- Dalli does not support Rails 2.x any longer.
90
-
91
-
92
- Usage with Passenger
93
- ------------------------
94
-
95
- Put this at the bottom of `config/environment.rb`:
96
-
97
- if defined?(PhusionPassenger)
98
- PhusionPassenger.on_event(:starting_worker_process) do |forked|
99
- # Reset Rails's object cache
100
- # Only works with DalliStore
101
- Rails.cache.reset if forked
102
-
103
- # Reset Rails's session store
104
- # If you know a cleaner way to find the session store instance, please let me know
105
- ObjectSpace.each_object(ActionDispatch::Session::DalliStore) { |obj| obj.reset }
106
- end
107
- end
108
-
109
-
110
- Configuration
111
- ------------------------
112
- Dalli::Client accepts the following options. All times are in seconds.
113
-
114
- **expires_in**: Global default for key TTL. No default.
115
-
116
- **failover**: Boolean, if true Dalli will failover to another server if the main server for a key is down.
117
-
118
- **compress**: Boolean, if true Dalli will gzip-compress values larger than 1K.
119
-
120
- **socket_timeout**: Timeout for all socket operations (connect, read, write). Default is 0.5.
121
-
122
- **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.
123
-
124
- **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.
125
-
126
- **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.
127
-
128
- **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.
129
-
130
- **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.
131
-
132
- **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.
133
-
134
- **keepalive**: Boolean, if true Dalli will enable keep-alives on the socket so inactivity
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).
135
16
 
136
- Features and Changes
137
- ------------------------
17
+ ![Persistence of Memory](https://upload.wikimedia.org/wikipedia/en/d/dd/The_Persistence_of_Memory.jpg)
138
18
 
139
- By default, Dalli is thread-safe. Disable thread-safety at your own peril.
140
19
 
141
- Note that Dalli does not require ActiveSupport or Rails. You can safely use it in your own Ruby projects.
20
+ ## Documentation and Information
142
21
 
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://www.rubydoc.info/gems/dalli) - Ruby documentation for the `Dalli::Client` API
143
27
 
144
- Helping Out
145
- -------------
28
+ ## Development
146
29
 
147
- 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.
30
+ After checking out the repo, run `bin/setup` to install dependencies. You can run `bin/console` for an interactive prompt that will allow you to experiment.
148
31
 
32
+ To install this gem onto your local machine, run `bundle exec rake install`.
149
33
 
150
- Thanks
151
- ------------
34
+ ## Contributing
152
35
 
153
- Eric Wong - for help using his [kgio](http://unicorn.bogomips.org/kgio/index.html) library.
36
+ 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.
154
37
 
155
- Brian Mitchell - for his remix-stash project which was helpful when implementing and testing the binary protocol support.
38
+ ## Appreciation
156
39
 
157
- [CouchBase](http://couchbase.com) - for their project sponsorship
40
+ Dalli would not exist in its current form without the contributions of many people. But special thanks go to several individuals and organizations:
158
41
 
42
+ * Mike Perham - for originally authoring the Dalli project and serving as maintainer and primary contributor for many years
43
+ * Eric Wong - for help using his [kgio](http://bogomips.org/kgio/) library.
44
+ * Brian Mitchell - for his remix-stash project which was helpful when implementing and testing the binary protocol support.
45
+ * [CouchBase](http://couchbase.com) - for their sponsorship of the original development
159
46
 
160
- Author
161
- ----------
162
47
 
163
- 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) or send a few bucks my way via my Pledgie page below. Happy caching!
48
+ ## Authors
164
49
 
165
- <a href='http://www.pledgie.com/campaigns/16623'><img alt='Click here to lend your support to Open Source and make a donation at www.pledgie.com !' src='http://www.pledgie.com/campaigns/16623.png?skin_name=chrome' border='0' /></a>
50
+ * [Peter M. Goldstein](https://github.com/petergoldstein) - current maintainer
51
+ * [Mike Perham](https://github.com/mperham) and contributors
166
52
 
167
53
 
168
- Copyright
169
- -----------
54
+ ## Copyright
170
55
 
171
- Copyright (c) 2012 Mike Perham. See LICENSE for details.
56
+ Copyright (c) Mike Perham, Peter M. Goldstein. See LICENSE for details.
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ puts "You can remove `require 'dalli/cas/client'` as this code has been rolled into the standard 'dalli/client'."