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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4049027dc5a512bb6f1225b179ac82989b995e8e77f0b384fce0154c58cd76c0
4
- data.tar.gz: 0351324db2bb6a5d00d2585d7e2fb52d5f1f17860f19ec56e23bc848d411ce0f
3
+ metadata.gz: 54fd4c438eab18c36f842002725ec243f6ca9837f03a2d70dc594a8bf4765d8d
4
+ data.tar.gz: cc5512b2fa88dd622da3ef9fae6abda48f9c7122eed828dd988a17343607f0cd
5
5
  SHA512:
6
- metadata.gz: 278e15de6e89c0a006c13da52ff42a326be704050ef905d8ad7c0541a8444359253923a9331747440f72fe2855ac7addf3af3b917c75c5a2775c052618aa62fb
7
- data.tar.gz: 9ec95ddb14b3a4d6763dd7ddd0e40b9f5367a3943baad464890b64723747b849627cbb513e1d3b982640563f3c73e1f18d8a437470e6303853369c07bf9b8154
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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ResponseBank
3
- VERSION = "1.6.0"
3
+ VERSION = "1.7.0"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: response_bank
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Lütke