readthis 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -0
- data/lib/readthis.rb +23 -0
- data/lib/readthis/cache.rb +2 -0
- data/lib/readthis/version.rb +1 -1
- data/spec/readthis/cache_spec.rb +11 -1
- data/spec/readthis_spec.rb +12 -0
- data/spec/spec_helper.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e47cddbb974aaa2df5258b6279db5ac65ac1b7c
|
4
|
+
data.tar.gz: d729c1a37bbd6b2ab51d20ff20944e4b51aab561
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b9e58cf2f1dda31681d653e770153d190b1fb5958e52881222b8a350cf94b71eac28c9043e56d1d2ab6673952db14b63872d52452006926cf2818d74837961d
|
7
|
+
data.tar.gz: f4950c2133cd938ee7e5b9da6a4ed5605506ef4da347b0b34379ad07b97fcc66d2c63dab6c56ddba72e41a4490313338517360860924bd7a5171fb9d21561b05
|
data/README.md
CHANGED
@@ -137,6 +137,19 @@ sticky and a flag is stored with each cached value. If you subsequently go to
|
|
137
137
|
deserialize values and haven't configured the same serializers in the same order
|
138
138
|
your application will raise errors.
|
139
139
|
|
140
|
+
## Fault Tolerance
|
141
|
+
|
142
|
+
In some situations it is desirable to keep serving requests from disk or the
|
143
|
+
database if Redis crashes. This can be achieved wiht connection fault tolerance
|
144
|
+
by enabling it at the top level:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
Readthis.fault_tolerant = true
|
148
|
+
```
|
149
|
+
|
150
|
+
The default value is `false`, because while it may work for `fetch` operations,
|
151
|
+
it isn't compatible with other state-based commands like `increment`.
|
152
|
+
|
140
153
|
## Differences From ActiveSupport::Cache
|
141
154
|
|
142
155
|
Readthis supports all of standard cache methods except for the following:
|
data/lib/readthis.rb
CHANGED
@@ -16,4 +16,27 @@ module Readthis
|
|
16
16
|
def serializers
|
17
17
|
@serializers ||= Readthis::Serializers.new
|
18
18
|
end
|
19
|
+
|
20
|
+
# Indicates whether connection error tolerance is enabled. With tolerance
|
21
|
+
# enabled every operation will return a `nil` value.
|
22
|
+
#
|
23
|
+
# @returns [Boolean] True for enabled, false for disabled
|
24
|
+
#
|
25
|
+
def fault_tolerant?
|
26
|
+
@fault_tolerant
|
27
|
+
end
|
28
|
+
|
29
|
+
# Toggle fault tolerance for connection errors.
|
30
|
+
#
|
31
|
+
# @param [Boolean] The new value for fault tolerance
|
32
|
+
#
|
33
|
+
def fault_tolerant=(value)
|
34
|
+
@fault_tolerant = value
|
35
|
+
end
|
36
|
+
|
37
|
+
# @private
|
38
|
+
def reset!
|
39
|
+
@fault_tolerant = nil
|
40
|
+
@serializers = nil
|
41
|
+
end
|
19
42
|
end
|
data/lib/readthis/cache.rb
CHANGED
data/lib/readthis/version.rb
CHANGED
data/spec/readthis/cache_spec.rb
CHANGED
@@ -48,7 +48,7 @@ RSpec.describe Readthis::Cache do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'uses a custom expiration' do
|
51
|
-
cache = Readthis::Cache.new(namespace: 'cache', expires_in:
|
51
|
+
cache = Readthis::Cache.new(namespace: 'cache', expires_in: 86_400)
|
52
52
|
|
53
53
|
cache.write('some-key', 'some-value')
|
54
54
|
cache.write('other-key', 'other-value', expires_in: 1)
|
@@ -166,6 +166,16 @@ RSpec.describe Readthis::Cache do
|
|
166
166
|
cache.write('great-key', 'great')
|
167
167
|
expect(cache.fetch('great-key', nil)).to eq('great')
|
168
168
|
end
|
169
|
+
|
170
|
+
it 'serves computed content when the cache is down and tolerance is enabled' do
|
171
|
+
Readthis.fault_tolerant = true
|
172
|
+
|
173
|
+
allow(cache.pool).to receive(:with).and_raise(Redis::CannotConnectError)
|
174
|
+
|
175
|
+
computed = cache.fetch('error-key') { 'computed' }
|
176
|
+
|
177
|
+
expect(computed).to eq('computed')
|
178
|
+
end
|
169
179
|
end
|
170
180
|
|
171
181
|
describe '#read_multi' do
|
data/spec/readthis_spec.rb
CHANGED
@@ -6,4 +6,16 @@ RSpec.describe Readthis do
|
|
6
6
|
expect(Readthis.serializers.marshals).to include(Marshal, JSON)
|
7
7
|
end
|
8
8
|
end
|
9
|
+
|
10
|
+
describe '#fault_tolerant?' do
|
11
|
+
it 'defaults to being false' do
|
12
|
+
expect(Readthis).not_to be_fault_tolerant
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'can be enabled' do
|
16
|
+
Readthis.fault_tolerant = true
|
17
|
+
|
18
|
+
expect(Readthis).to be_fault_tolerant
|
19
|
+
end
|
20
|
+
end
|
9
21
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: readthis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Parker Selbert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|