Class: Async::HTTP::Cache::Response
- Inherits:
-
Protocol::HTTP::Response
- Object
- Protocol::HTTP::Response
- Async::HTTP::Cache::Response
- Defined in:
- lib/async/http/cache/response.rb
Constant Summary collapse
- CACHE_CONTROL =
'cache-control'
- ETAG =
'etag'
- X_CACHE =
'x-cache'
Instance Attribute Summary collapse
-
#generated_at ⇒ Object
readonly
Returns the value of attribute generated_at.
Instance Method Summary collapse
- #age ⇒ Object
- #dup ⇒ Object
- #etag ⇒ Object
- #expired? ⇒ Boolean
-
#initialize(response, body) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(response, body) ⇒ Response
Returns a new instance of Response.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/async/http/cache/response.rb', line 18 def initialize(response, body) @generated_at = Async::Clock.now super( response.version, response.status, response.headers.flatten, body, response.protocol ) @max_age = @headers[CACHE_CONTROL]&.max_age @etag = nil @headers.set(X_CACHE, 'hit') end |
Instance Attribute Details
#generated_at ⇒ Object (readonly)
Returns the value of attribute generated_at.
35 36 37 |
# File 'lib/async/http/cache/response.rb', line 35 def generated_at @generated_at end |
Instance Method Details
#age ⇒ Object
41 42 43 |
# File 'lib/async/http/cache/response.rb', line 41 def age Async::Clock.now - @generated_at end |
#dup ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/async/http/cache/response.rb', line 51 def dup dup = super dup.body = @body.dup dup.headers = @headers.dup return dup end |
#etag ⇒ Object
37 38 39 |
# File 'lib/async/http/cache/response.rb', line 37 def etag @etag ||= @headers[ETAG] end |
#expired? ⇒ Boolean
45 46 47 48 49 |
# File 'lib/async/http/cache/response.rb', line 45 def expired? if @max_age self.age > @max_age end end |