Class: Resourceful::CacheEntry
- Defined in:
- lib/resourceful/cache_manager.rb
Overview
Represents a previous request and cached response with enough detail to determine construct a cached response to a matching request in the future. It also understands what a matching request means.
Instance Attribute Summary collapse
-
#request_time ⇒ Object
readonly
The time at which the client believes the request was made.
-
#request_uri ⇒ Object
readonly
The URI of the request.
-
#request_vary_headers ⇒ Object
readonly
request_vary_headers is a HttpHeader with keys from the Vary header of the response, plus the values from the matching fields in the request.
-
#response ⇒ Object
readonly
The response to that we are caching.
Instance Method Summary collapse
-
#initialize(request, response) ⇒ CacheEntry
constructor
A new instance of CacheEntry.
-
#select_request_headers(request, response) ⇒ Object
Selects the headers from the request named by the response’s Vary header www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.5.6.
-
#valid_for?(request) ⇒ Boolean
Returns true if this entry may be used to fullfil the given request, according to the vary headers.
Constructor Details
#initialize(request, response) ⇒ CacheEntry
Returns a new instance of CacheEntry.
204 205 206 207 208 209 |
# File 'lib/resourceful/cache_manager.rb', line 204 def initialize(request, response) @request_uri = request.uri @request_time = request.request_time @request_vary_headers = select_request_headers(request, response) @response = response end |
Instance Attribute Details
#request_time ⇒ Object (readonly)
The time at which the client believes the request was made.
192 193 194 |
# File 'lib/resourceful/cache_manager.rb', line 192 def request_time @request_time end |
#request_uri ⇒ Object (readonly)
The URI of the request
195 196 197 |
# File 'lib/resourceful/cache_manager.rb', line 195 def request_uri @request_uri end |
#request_vary_headers ⇒ Object (readonly)
request_vary_headers is a HttpHeader with keys from the Vary header of the response, plus the values from the matching fields in the request
189 190 191 |
# File 'lib/resourceful/cache_manager.rb', line 189 def request_vary_headers @request_vary_headers end |
#response ⇒ Object (readonly)
The response to that we are caching
198 199 200 |
# File 'lib/resourceful/cache_manager.rb', line 198 def response @response end |
Instance Method Details
#select_request_headers(request, response) ⇒ Object
Selects the headers from the request named by the response’s Vary header www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.5.6
230 231 232 233 234 235 236 237 238 |
# File 'lib/resourceful/cache_manager.rb', line 230 def select_request_headers(request, response) header = Resourceful::Header.new response.header['Vary'].each do |name| header[name] = request.header[name] if request.header[name] end if response.header['Vary'] header end |
#valid_for?(request) ⇒ Boolean
Returns true if this entry may be used to fullfil the given request, according to the vary headers.
216 217 218 219 220 221 |
# File 'lib/resourceful/cache_manager.rb', line 216 def valid_for?(request) request.uri == @request_uri and @request_vary_headers.all? {|key, value| request.header[key] == value } end |