Class: HTTP::Features::Caching::Entry
- Inherits:
-
Object
- Object
- HTTP::Features::Caching::Entry
- Defined in:
- lib/http/features/caching/entry.rb
Overview
A cached response entry with freshness logic
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
The response body as a string.
-
#headers ⇒ HTTP::Headers
readonly
The response headers.
-
#proxy_headers ⇒ HTTP::Headers
readonly
The proxy headers from the original response.
-
#request_uri ⇒ HTTP::URI
readonly
The URI of the original request.
-
#status ⇒ Integer
readonly
The HTTP status code.
-
#stored_at ⇒ Time
readonly
When the response was stored.
-
#version ⇒ String
readonly
The HTTP version.
Instance Method Summary collapse
-
#fresh? ⇒ Boolean
Whether the cached response is still fresh.
-
#initialize(status:, version:, headers:, proxy_headers:, body:, request_uri:, stored_at:) ⇒ Entry
constructor
Create a new cache entry.
-
#revalidate! ⇒ Time
Reset the stored_at time to now (after successful revalidation).
-
#update_headers!(response_headers) ⇒ void
Merge response headers from a 304 revalidation into the stored entry.
Constructor Details
#initialize(status:, version:, headers:, proxy_headers:, body:, request_uri:, stored_at:) ⇒ Entry
Create a new cache entry
89 90 91 92 93 94 95 96 97 |
# File 'lib/http/features/caching/entry.rb', line 89 def initialize(status:, version:, headers:, proxy_headers:, body:, request_uri:, stored_at:) @status = status @version = version @headers = headers @proxy_headers = proxy_headers @body = body @request_uri = request_uri @stored_at = stored_at end |
Instance Attribute Details
#body ⇒ String (readonly)
The response body as a string
53 54 55 |
# File 'lib/http/features/caching/entry.rb', line 53 def body @body end |
#headers ⇒ HTTP::Headers (readonly)
The response headers
35 36 37 |
# File 'lib/http/features/caching/entry.rb', line 35 def headers @headers end |
#proxy_headers ⇒ HTTP::Headers (readonly)
The proxy headers from the original response
44 45 46 |
# File 'lib/http/features/caching/entry.rb', line 44 def proxy_headers @proxy_headers end |
#request_uri ⇒ HTTP::URI (readonly)
The URI of the original request
62 63 64 |
# File 'lib/http/features/caching/entry.rb', line 62 def request_uri @request_uri end |
#status ⇒ Integer (readonly)
The HTTP status code
17 18 19 |
# File 'lib/http/features/caching/entry.rb', line 17 def status @status end |
#stored_at ⇒ Time (readonly)
When the response was stored
71 72 73 |
# File 'lib/http/features/caching/entry.rb', line 71 def stored_at @stored_at end |
#version ⇒ String (readonly)
The HTTP version
26 27 28 |
# File 'lib/http/features/caching/entry.rb', line 26 def version @version end |
Instance Method Details
#fresh? ⇒ Boolean
Whether the cached response is still fresh
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/http/features/caching/entry.rb', line 106 def fresh? return false if no_cache? ttl = max_age return age < ttl if ttl expires = expires_at return Time.now < expires if expires false end |
#revalidate! ⇒ Time
Reset the stored_at time to now (after successful revalidation)
125 126 127 |
# File 'lib/http/features/caching/entry.rb', line 125 def revalidate! @stored_at = Time.now end |
#update_headers!(response_headers) ⇒ void
This method returns an undefined value.
Merge response headers from a 304 revalidation into the stored entry
137 138 139 |
# File 'lib/http/features/caching/entry.rb', line 137 def update_headers!(response_headers) response_headers.each { |name, value| @headers[name] = value } # steep:ignore end |