Class: Capybara::Simulated::AssetCache::Entry

Inherits:
Struct
  • Object
show all
Defined in:
lib/capybara/simulated/asset_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



44
45
46
# File 'lib/capybara/simulated/asset_cache.rb', line 44

def body
  @body
end

#headersObject

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



44
45
46
# File 'lib/capybara/simulated/asset_cache.rb', line 44

def headers
  @headers
end

#immutableObject

Returns the value of attribute immutable

Returns:

  • (Object)

    the current value of immutable



44
45
46
# File 'lib/capybara/simulated/asset_cache.rb', line 44

def immutable
  @immutable
end

#max_ageObject

Returns the value of attribute max_age

Returns:

  • (Object)

    the current value of max_age



44
45
46
# File 'lib/capybara/simulated/asset_cache.rb', line 44

def max_age
  @max_age
end

#no_cacheObject

Returns the value of attribute no_cache

Returns:

  • (Object)

    the current value of no_cache



44
45
46
# File 'lib/capybara/simulated/asset_cache.rb', line 44

def no_cache
  @no_cache
end

#statusObject

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



44
45
46
# File 'lib/capybara/simulated/asset_cache.rb', line 44

def status
  @status
end

#stored_atObject

Returns the value of attribute stored_at

Returns:

  • (Object)

    the current value of 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.

Returns:

  • (Boolean)


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