rack-cache 1.11.0 → 1.13.0
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.
- checksums.yaml +4 -4
- data/CHANGES +8 -0
- data/README.md +2 -2
- data/lib/rack/cache/context.rb +22 -5
- data/lib/rack/cache/key.rb +1 -1
- data/lib/rack/cache/meta_store.rb +5 -4
- data/lib/rack/cache/options.rb +5 -0
- data/lib/rack/cache/response.rb +1 -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: 2d031263204dbdf38df4290dfcda6ebf48f349d69b6499a878e616a18f0ff914
|
4
|
+
data.tar.gz: a4153ac38a62c88f8bae3e760d1a903dfbb1ba641f086d1dbd32bca20a81d118
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c627fb81cd7eee48a3d54d9a07942b8b62b1fd480d1a89bfc58a717fd400a8f7e2d8453c336e2090c9bed92f410bf1f31a3bbe6a49f42d7b262e0da81c98b55d
|
7
|
+
data.tar.gz: 9329f2fd9d67707fd984a0dc9c8fc9030687d3b08e3a1a34a4efc168e5840d97be4dc065a3af6e7516ca821d1cf285ef7a29562b3d84788e6ae200b19c86b7c9
|
data/CHANGES
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 1.12.0
|
2
|
+
|
3
|
+
* Add a fault_tolerant flag to fail-over to stale cache
|
4
|
+
|
5
|
+
## 1.11.1
|
6
|
+
|
7
|
+
* when ignoring parts of the query, remove query in key when all params are ignored
|
8
|
+
|
1
9
|
## 1.11.0
|
2
10
|
|
3
11
|
* Add a proc to allow ignoring parts of the query string in the key
|
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/key.rb
CHANGED
@@ -34,7 +34,7 @@ module Rack::Cache
|
|
34
34
|
|
35
35
|
# find a cached entry that matches the request.
|
36
36
|
env = request.env
|
37
|
-
match = entries.detect{|req,res| requests_match?(res['Vary'], env, req)}
|
37
|
+
match = entries.detect{ |req,res| requests_match?((res['Vary'] || res['vary']), env, req) }
|
38
38
|
return nil if match.nil?
|
39
39
|
|
40
40
|
_, res = match
|
@@ -90,13 +90,14 @@ module Rack::Cache
|
|
90
90
|
# the list
|
91
91
|
vary = response.vary
|
92
92
|
entries =
|
93
|
-
read(key).reject do |env,res|
|
94
|
-
(vary == res['Vary']) &&
|
93
|
+
read(key).reject do |env, res|
|
94
|
+
(vary == (res['Vary'] || res['vary'])) &&
|
95
95
|
requests_match?(vary, env, stored_env)
|
96
96
|
end
|
97
97
|
|
98
98
|
headers = persist_response(response)
|
99
|
-
headers.delete
|
99
|
+
headers.delete('Age')
|
100
|
+
headers.delete('age')
|
100
101
|
|
101
102
|
entries.unshift [stored_env, headers]
|
102
103
|
if request.env['rack-cache.use_native_ttl'] && response.fresh?
|
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
|
data/lib/rack/cache/response.rb
CHANGED
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.13.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:
|
11
|
+
date: 2021-09-26 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.2.16
|
167
167
|
signing_key:
|
168
168
|
specification_version: 4
|
169
169
|
summary: HTTP Caching for Rack
|