Class: Async::HTTP::Cache::Response

Inherits:
Protocol::HTTP::Response
  • Object
show all
Defined in:
lib/async/http/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_atObject (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

#ageObject



64
65
66
# File 'lib/async/http/cache.rb', line 64

def age
	Async::Clock.now - @generated_at
end

#cachable?Boolean

Returns:

  • (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

#dupObject



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

Returns:

  • (Boolean)


68
69
70
# File 'lib/async/http/cache.rb', line 68

def expired?
	self.age > @max_age
end