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.



190
191
192
# File 'lib/httpx/plugins/response_cache.rb', line 190

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)


203
204
205
# File 'lib/httpx/plugins/response_cache.rb', line 203

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

#initializeObject



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

def initialize(*)
  super
  @cached_response = nil
end

#merge_headersObject



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

def merge_headers(*)
  super
  @response_cache_key = nil
end

#response_cache_keyObject

returns a unique cache key as a String identifying this request



208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/httpx/plugins/response_cache.rb', line 208

def response_cache_key
  @response_cache_key ||= begin
    keys = [@verb, @uri.merge(path)]

    @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