Module: HTTPX::Plugins::ResponseCache::RequestMethods

Defined in:
lib/httpx/plugins/response_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cached_responseObject

points to a previously cached Response corresponding to this request.



185
186
187
# File 'lib/httpx/plugins/response_cache.rb', line 185

def cached_response
  @cached_response
end

Instance Method Details

#cacheable_verb?Boolean

returns whether this request is cacheable as per HTTP caching rules.

Returns:

  • (Boolean)


198
199
200
# File 'lib/httpx/plugins/response_cache.rb', line 198

def cacheable_verb?
  CACHEABLE_VERBS.include?(@verb)
end

#initializeObject



187
188
189
190
# File 'lib/httpx/plugins/response_cache.rb', line 187

def initialize(*)
  super
  @cached_response = nil
end

#merge_headersObject



192
193
194
195
# File 'lib/httpx/plugins/response_cache.rb', line 192

def merge_headers(*)
  super
  @response_cache_key = nil
end

#response_cache_keyObject

returns a unique cache key as a String identifying this request



203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/httpx/plugins/response_cache.rb', line 203

def response_cache_key
  @response_cache_key ||= begin
    keys = [@verb, @uri]

    @options.supported_vary_headers.each do |field|
      value = @headers[field]

      keys << value if value
    end
    Digest::SHA1.hexdigest("httpx-response-cache-#{keys.join("-")}")
  end
end