class HTTP::Request::Caching

Decorator for requests to provide convenience methods related to caching.

def cache_headers

Other tags:
    Api: - public

Returns:
  • (HTTP::Cache::Headers) - cache control helper for this request
def cache_headers
  @cache_headers ||= HTTP::Cache::Headers.new headers
end

def cacheable?

Other tags:
    Api: - public

Returns:
  • (Boolean) - true if request is cacheable
def cacheable?
  CACHEABLE_METHODS.include?(verb) &&
    !cache_headers.no_store?
end

def caching

Returns:
  • (HTTP::Request::Caching) -
def caching
  self
end

def conditional_headers_for(cached_response)

Other tags:
    Api: - private

Returns:
  • (Headers) - conditional request headers
def conditional_headers_for(cached_response)
  headers = HTTP::Headers.new
  cached_response.headers.get("Etag").
    each { |etag| headers.add("If-None-Match", etag) }
  cached_response.headers.get("Last-Modified").
    each { |last_mod| headers.add("If-Modified-Since", last_mod) }
  headers.add("Cache-Control", "max-age=0") if cache_headers.forces_revalidation?
  headers
end

def conditional_on_changes_to(cached_response)

Other tags:
    Api: - public

Returns:
  • (HTTP::Request::Caching) - new request based on this
def conditional_on_changes_to(cached_response)
  self.class.new HTTP::Request.new(
    verb, uri, headers.merge(conditional_headers_for(cached_response)),
    proxy, body, version).caching
end

def env

def env
  {"rack-cache.cache_key" => lambda { |r| r.uri.to_s }}
end

def initialize(obj)

Other tags:
    Api: - private
def initialize(obj)
  super
  @requested_at = nil
  @received_at  = nil
end

def invalidates_cache?

Other tags:
    Api: - public

Returns:
  • (Boolean) - true iff request demands the resources cache entry be invalidated
def invalidates_cache?
  INVALIDATING_METHODS.include?(verb) ||
    cache_headers.no_store?
end

def skips_cache?

Other tags:
    Api: - public

Returns:
  • (Boolean) - true iff the cache control info of this
def skips_cache?
  0 == cache_headers.max_age       ||
    cache_headers.must_revalidate? ||
    cache_headers.no_cache?
end