Class: HTTP::Request::Caching

### Home Classes Methods

### In Files

- lib/http/request/caching.rb

### Parent

DelegateClass(HTTP::Request)

### Methods

- ::new
- #cache_headers
- #cacheable?
- #caching
- #conditional_on_changes_to
- #env
- #invalidates_cache?
- #skips_cache?

### Class/Module Index

Quicksearch

- HTTP
- HTTP::Cache
- HTTP::Cache::Headers
- HTTP::Cache::NullCache
- HTTP::Cache::NullLogger
- HTTP::CacheError
- HTTP::Chainable
- HTTP::Client
- HTTP::Connection
- HTTP::Error
- HTTP::Headers
- HTTP::Headers::Mixin
- HTTP::InvalidHeaderNameError
- HTTP::MimeType
- HTTP::MimeType::Adapter
- HTTP::MimeType::JSON
- HTTP::Options
- HTTP::Redirector
- HTTP::Redirector::EndlessRedirectError
- HTTP::Redirector::TooManyRedirectsError
- HTTP::Request
- HTTP::Request::Caching
- HTTP::Request::UnsupportedMethodError
- HTTP::Request::UnsupportedSchemeError
- HTTP::Request::Writer
- HTTP::RequestError
- HTTP::Response
- HTTP::Response::Body
- HTTP::Response::Caching
- HTTP::Response::IoBody
- HTTP::Response::Parser
- HTTP::Response::Status
- HTTP::Response::StringBody
- HTTP::ResponseError
- HTTP::StateError
- HTTP::Timeout
- HTTP::Timeout::Global
- HTTP::Timeout::Null
- HTTP::Timeout::PerOperation
- HTTP::TimeoutError
- HTTP::URI
- Object

No matching classes.

# HTTP::Request::Caching

Decorator for requests to provide convenience methods related to caching.

### Constants

CACHEABLE_METHODS
INVALIDATING_METHODS

### Attributes

sent_at[RW]

When was this request sent to the server

@api public

### Public Class Methods

new(obj) click to toggle source

Inits a new instance @api private

    # File lib/http/request/caching.rb, line 18
    def initialize(obj)
      super
      @requested_at = nil
      @received_at  = nil
    end

### Public Instance Methods

cache_headers() click to toggle source

@return [HTTP::Cache::Headers] cache control helper for this request @api public

    # File lib/http/request/caching.rb, line 69
    def cache_headers
      @cache_headers ||= HTTP::Cache::Headers.new headers
    end

cacheable?() click to toggle source

@return [Boolean] true if request is cacheable

@api public

    # File lib/http/request/caching.rb, line 40
    def cacheable?
      CACHEABLE_METHODS.include?(verb) &&
        !cache_headers.no_store?
    end

caching() click to toggle source

@return [HTTP::Request::Caching]

    # File lib/http/request/caching.rb, line 25
    def caching
      self
    end

conditional_on_changes_to(cached_response) click to toggle source

@return [HTTP::Request::Caching] new request based on this one but conditional on the resource having changed since `cached_response`

@api public

    # File lib/http/request/caching.rb, line 61
    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

env() click to toggle source

    # File lib/http/request/caching.rb, line 73
    def env
      {"rack-cache.cache_key" => lambda { |r| r.uri.to_s }}
    end

invalidates_cache?() click to toggle source

@return [Boolean] true iff request demands the resources cache entry be invalidated

@api public

    # File lib/http/request/caching.rb, line 32
    def invalidates_cache?
      INVALIDATING_METHODS.include?(verb) ||
        cache_headers.no_store?
    end

skips_cache?() click to toggle source

@return [Boolean] true iff the cache control info of this request demands that the response be revalidated by the origin server.

@api public

    # File lib/http/request/caching.rb, line 50
    def skips_cache?
      0 == cache_headers.max_age       ||
        cache_headers.must_revalidate? ||
        cache_headers.no_cache?
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.