Class: Async::HTTP::Cache::Response
- Inherits:
-
Protocol::HTTP::Response
- Object
- Protocol::HTTP::Response
- Async::HTTP::Cache::Response
- Defined in:
- lib/async/http/cache.rb
Instance Attribute Summary collapse
-
#generated_at ⇒ Object
readonly
Returns the value of attribute generated_at.
Instance Method Summary collapse
- #age ⇒ Object
- #cachable? ⇒ Boolean
- #dup ⇒ 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.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/async/http/cache.rb', line 36 def initialize(response, body) @generated_at = Async::Clock.now super( response.version, response.status, response.headers.dup, body, response.protocol ) @max_age = @headers[CACHE_CONTROL]&.max_age end |
Instance Attribute Details
#generated_at ⇒ Object (readonly)
Returns the value of attribute generated_at.
62 63 64 |
# File 'lib/async/http/cache.rb', line 62 def generated_at @generated_at end |
Instance Method Details
#age ⇒ Object
64 65 66 |
# File 'lib/async/http/cache.rb', line 64 def age Async::Clock.now - @generated_at end |
#cachable? ⇒ Boolean
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/async/http/cache.rb', line 50 def cachable? if cache_control = @headers[CACHE_CONTROL] if cache_control.private? return false end if cache_control.public? return true end end end |
#dup ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/async/http/cache.rb', line 72 def dup dup = super dup.body = @body.dup dup.headers = @headers.dup return dup end |
#expired? ⇒ Boolean
68 69 70 |
# File 'lib/async/http/cache.rb', line 68 def expired? self.age > @max_age end |