Class: Capybara::Simulated::AssetCache::Entry
- Inherits:
-
Struct
- Object
- Struct
- Capybara::Simulated::AssetCache::Entry
- Defined in:
- lib/capybara/simulated/asset_cache.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#immutable ⇒ Object
Returns the value of attribute immutable.
-
#max_age ⇒ Object
Returns the value of attribute max_age.
-
#no_cache ⇒ Object
Returns the value of attribute no_cache.
-
#status ⇒ Object
Returns the value of attribute status.
-
#stored_at ⇒ Object
Returns the value of attribute stored_at.
Instance Method Summary collapse
-
#fresh?(now = Time.now) ⇒ Boolean
‘must-revalidate` (RFC 9111 §5.2.2.2) only forbids reusing a response *once it has become stale* without revalidation — it does NOT force revalidation while the entry is still fresh, and this cache never serves a stale entry without revalidating anyway (lookup falls through to a conditional re-dispatch).
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body
44 45 46 |
# File 'lib/capybara/simulated/asset_cache.rb', line 44 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers
44 45 46 |
# File 'lib/capybara/simulated/asset_cache.rb', line 44 def headers @headers end |
#immutable ⇒ Object
Returns the value of attribute immutable
44 45 46 |
# File 'lib/capybara/simulated/asset_cache.rb', line 44 def immutable @immutable end |
#max_age ⇒ Object
Returns the value of attribute max_age
44 45 46 |
# File 'lib/capybara/simulated/asset_cache.rb', line 44 def max_age @max_age end |
#no_cache ⇒ Object
Returns the value of attribute no_cache
44 45 46 |
# File 'lib/capybara/simulated/asset_cache.rb', line 44 def no_cache @no_cache end |
#status ⇒ Object
Returns the value of attribute status
44 45 46 |
# File 'lib/capybara/simulated/asset_cache.rb', line 44 def status @status end |
#stored_at ⇒ Object
Returns the value of attribute stored_at
44 45 46 |
# File 'lib/capybara/simulated/asset_cache.rb', line 44 def stored_at @stored_at end |
Instance Method Details
#fresh?(now = Time.now) ⇒ Boolean
‘must-revalidate` (RFC 9111 §5.2.2.2) only forbids reusing a response *once it has become stale* without revalidation — it does NOT force revalidation while the entry is still fresh, and this cache never serves a stale entry without revalidating anyway (lookup falls through to a conditional re-dispatch). So `must-revalidate` has no effect on freshness here. Only `no-cache` (§5.2.2.4), which requires validation before EVERY use, blocks a fresh entry. Conflating the two made Vite/Rails assets (`max-age=2419200, must-revalidate`) revalidate on every fetch instead of being served fresh like a real browser does.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/capybara/simulated/asset_cache.rb', line 55 def fresh?(now = Time.now) return false if no_cache # `max-age=0` (or absent) means the response is stale on arrival — # a cache MUST revalidate before reuse (RFC 9111 §5.2.1.1). Ruby's # `0` is truthy, so the value must be guarded explicitly; without # `positive?`, a `max-age=0, must-revalidate` response (e.g. Forem's # per-user `/async_info/base_data`, `/notifications/counts`) would be # treated as fresh and served stale instead of revalidated. return false unless max_age&.positive? (now - stored_at) < max_age end |