response_bank 1.6.0 → 1.7.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/README.md +13 -0
- data/lib/response_bank/response_cache_handler.rb +3 -0
- data/lib/response_bank/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 54fd4c438eab18c36f842002725ec243f6ca9837f03a2d70dc594a8bf4765d8d
|
|
4
|
+
data.tar.gz: cc5512b2fa88dd622da3ef9fae6abda48f9c7122eed828dd988a17343607f0cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9637541060aab3ac047247fdd13e83d57b99e3921689a7dd354ce684c247f9decb04de2c784e6f04bb57796e71279098a2f1a3db670d67ad25bb8406a7eb30f3
|
|
7
|
+
data.tar.gz: d3ba8c122b58152cd1e10e8d1fb504b65c2e8c906d3a862be98050f7b252129d392bbc83d0e220a2c79248f0da16bb3f85d8ae441c0c2b03281ee123a872b4bf
|
data/README.md
CHANGED
|
@@ -305,6 +305,19 @@ Advanced integrations can still install the per-request injector directly in the
|
|
|
305
305
|
env[ResponseBank::BrotliSpliceSlot::INJECTOR_ENV_KEY] = injector
|
|
306
306
|
```
|
|
307
307
|
|
|
308
|
+
## Observing server cache hits
|
|
309
|
+
|
|
310
|
+
After successfully serving an entry from the server cache, ResponseBank exposes its generation time and stale-while-revalidate status in the Rack environment:
|
|
311
|
+
|
|
312
|
+
```ruby
|
|
313
|
+
timestamp = env['cacheable.timestamp']
|
|
314
|
+
stale = env['cacheable.stale']
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
`cacheable.timestamp` is only set after successfully serving a server-cache entry.
|
|
318
|
+
`cacheable.stale` is initialized to `false` when a server-cache entry is evaluated
|
|
319
|
+
and set to `true` only when ResponseBank serves it through stale-while-revalidate.
|
|
320
|
+
|
|
308
321
|
## Exception Handling
|
|
309
322
|
|
|
310
323
|
ResponseBank handles all exceptions gracefully during cache operations. If an exception occurs while reading from cache, deserializing cached data, or writing to cache, the middleware will:
|
|
@@ -133,6 +133,7 @@ module ResponseBank
|
|
|
133
133
|
@env['cacheable.compression_level'] = compression_level
|
|
134
134
|
|
|
135
135
|
@env['cacheable.locked'] ||= false
|
|
136
|
+
@env['cacheable.stale'] = false
|
|
136
137
|
|
|
137
138
|
# to preserve the unversioned/versioned logging messages from past releases we split the match_entity_tag test
|
|
138
139
|
if match_entity_tag == "*"
|
|
@@ -149,6 +150,7 @@ module ResponseBank
|
|
|
149
150
|
return
|
|
150
151
|
elsif stale_while_revalidate?(timestamp, cache_age_tolerance)
|
|
151
152
|
# cache is being regenerated, can we avoid piling on and use a stale version in the interim?
|
|
153
|
+
@env['cacheable.stale'] = true
|
|
152
154
|
ResponseBank.log("Cache hit: server (recent)")
|
|
153
155
|
else
|
|
154
156
|
ResponseBank.log("Found an unversioned cache entry, but it was too old (#{timestamp})")
|
|
@@ -184,6 +186,7 @@ module ResponseBank
|
|
|
184
186
|
@env.delete(ResponseBank::METADATA_ENV_KEY)
|
|
185
187
|
end
|
|
186
188
|
|
|
189
|
+
@env['cacheable.timestamp'] = timestamp
|
|
187
190
|
[status, @headers, [body]]
|
|
188
191
|
|
|
189
192
|
end
|