rack-cache 1.11.1 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +4 -0
- data/README.md +2 -2
- data/lib/rack/cache/context.rb +22 -5
- data/lib/rack/cache/options.rb +5 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb5dc6e1debaa841064dcf380a8015f6f63568187fda3ede9da81ed8d84041ec
|
4
|
+
data.tar.gz: 96c26c225e307ddaeaf6f8cbd5d219b0dacdcf18d9b36b11282af98a458af8be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b28a19dbb93f8eddce6bc7ab9e8307c9222c21131e5340db30b132c119ac8dbfd7079801365dbf987c68676f7605b26daab9bb03f996d2128c4ee9153a10006b
|
7
|
+
data.tar.gz: 4b810c3911b1e37dba674188165553c179da277f1ef0a7dd804afa8bc037f956f00322cfab0ab2d22a0e30e7ce44fb5eb1d07401c64b8b8c91f760c0a3c12b2c
|
data/CHANGES
CHANGED
data/README.md
CHANGED
@@ -16,7 +16,7 @@ validation (Last-Modified, ETag) information:
|
|
16
16
|
|
17
17
|
For more information about Rack::Cache features and usage, see:
|
18
18
|
|
19
|
-
|
19
|
+
https://rtomayko.github.com/rack-cache/
|
20
20
|
|
21
21
|
Rack::Cache is not overly optimized for performance. The main goal of the
|
22
22
|
project is to provide a portable, easy-to-configure, and standards-based
|
@@ -70,7 +70,7 @@ You should now see `Rack::Cache` listed in the middleware pipeline:
|
|
70
70
|
|
71
71
|
rake middleware
|
72
72
|
|
73
|
-
[more information](
|
73
|
+
[more information](https://snippets.aktagon.com/snippets/302-how-to-setup-and-use-rack-cache-with-rails)
|
74
74
|
|
75
75
|
Using with Dalli
|
76
76
|
----------------
|
data/lib/rack/cache/context.rb
CHANGED
@@ -161,10 +161,12 @@ module Rack::Cache
|
|
161
161
|
end
|
162
162
|
|
163
163
|
# Try to serve the response from cache. When a matching cache entry is
|
164
|
-
# found and is fresh, use it as the response without forwarding any
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
164
|
+
# found and is fresh, use it as the response without forwarding any request
|
165
|
+
# to the backend. When a matching cache entry is found but is stale, attempt
|
166
|
+
# to #validate the entry with the backend using conditional GET.
|
167
|
+
# If validation raises an exception and fault tolerant caching is enabled,
|
168
|
+
# serve the stale cache entry.
|
169
|
+
# When no matching cache entry is found, trigger miss processing.
|
168
170
|
def lookup
|
169
171
|
if @request.no_cache? && allow_reload?
|
170
172
|
record :reload
|
@@ -183,7 +185,11 @@ module Rack::Cache
|
|
183
185
|
entry
|
184
186
|
else
|
185
187
|
record :stale
|
186
|
-
|
188
|
+
if fault_tolerant?
|
189
|
+
validate_with_stale_cache_failover(entry)
|
190
|
+
else
|
191
|
+
validate(entry)
|
192
|
+
end
|
187
193
|
end
|
188
194
|
else
|
189
195
|
record :miss
|
@@ -192,6 +198,17 @@ module Rack::Cache
|
|
192
198
|
end
|
193
199
|
end
|
194
200
|
|
201
|
+
# Returns stale cache on exception.
|
202
|
+
def validate_with_stale_cache_failover(entry)
|
203
|
+
validate(entry)
|
204
|
+
rescue => e
|
205
|
+
record :connnection_failed
|
206
|
+
age = entry.age.to_s
|
207
|
+
entry.headers['Age'] = age
|
208
|
+
record "Fail-over to stale cache data with age #{age} due to #{e.class.name}: #{e}"
|
209
|
+
entry
|
210
|
+
end
|
211
|
+
|
195
212
|
# Validate that the cache entry is fresh. The original request is used
|
196
213
|
# as a template for a conditional GET request with the backend.
|
197
214
|
def validate(entry)
|
data/lib/rack/cache/options.rb
CHANGED
@@ -107,6 +107,10 @@ module Rack::Cache
|
|
107
107
|
# be used.
|
108
108
|
option_accessor :use_native_ttl
|
109
109
|
|
110
|
+
# Specifies whether to serve a request from a stale cache entry if
|
111
|
+
# the attempt to revalidate the cache entry raises an exception.
|
112
|
+
option_accessor :fault_tolerant
|
113
|
+
|
110
114
|
# The underlying options Hash. During initialization (or outside of a
|
111
115
|
# request), this is a default values Hash. During a request, this is the
|
112
116
|
# Rack environment Hash. The default values Hash is merged in underneath
|
@@ -149,6 +153,7 @@ module Rack::Cache
|
|
149
153
|
'rack-cache.allow_reload' => false,
|
150
154
|
'rack-cache.allow_revalidate' => false,
|
151
155
|
'rack-cache.use_native_ttl' => false,
|
156
|
+
'rack-cache.fault_tolerant' => false,
|
152
157
|
}
|
153
158
|
self.options = options
|
154
159
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Tomayko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
163
|
- !ruby/object:Gem::Version
|
164
164
|
version: '0'
|
165
165
|
requirements: []
|
166
|
-
rubygems_version: 3.
|
166
|
+
rubygems_version: 3.1.3
|
167
167
|
signing_key:
|
168
168
|
specification_version: 4
|
169
169
|
summary: HTTP Caching for Rack
|