Class: Rack::Client::Cache::Response

Inherits:
Response
  • Object
show all
Includes:
Response::Helpers
Defined in:
lib/rack/client/cache/response.rb

Constant Summary collapse

CACHEABLE_RESPONSE_CODES =

Status codes of responses that MAY be stored by a cache or used in reply to a subsequent request.

tools.ietf.org/html/rfc2616#section-13.4

[
  200, # OK
  203, # Non-Authoritative Information
  300, # Multiple Choices
  301, # Moved Permanently
  302, # Found
  404, # Not Found
  410  # Gone
].to_set

Instance Method Summary collapse

Methods inherited from Response

#initialize

Constructor Details

This class inherits a constructor from Rack::Client::Response

Instance Method Details

#cache_controlObject

A Hash of name=value pairs that correspond to the Cache-Control header. Valueless parameters (e.g., must-revalidate, no-store) have a Hash value of true. This method always returns a Hash, empty if no Cache-Control header is present.



31
32
33
# File 'lib/rack/client/cache/response.rb', line 31

def cache_control
  @cache_control ||= CacheControl.new(headers['Cache-Control'])
end

#cacheable?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
# File 'lib/rack/client/cache/response.rb', line 35

def cacheable?
  return false unless CACHEABLE_RESPONSE_CODES.include?(status)
  return false if cache_control.no_store? || cache_control.private?
  validateable? || fresh?
end

#etagObject

The literal value of ETag HTTP header or nil if no ETag is specified.



42
43
44
# File 'lib/rack/client/cache/response.rb', line 42

def etag
  headers['ETag']
end

#not_modified?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/rack/client/cache/response.rb', line 7

def not_modified?
  status == 304
end

#validateable?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/rack/client/cache/response.rb', line 46

def validateable?
  headers.key?('Last-Modified') || headers.key?('ETag')
end

#varyObject

The literal value of the Vary header, or nil when no header is present.



51
52
53
# File 'lib/rack/client/cache/response.rb', line 51

def vary
  headers['Vary']
end

#vary?Boolean

Does the response include a Vary header?

Returns:

  • (Boolean)


56
57
58
# File 'lib/rack/client/cache/response.rb', line 56

def vary?
  ! vary.nil?
end