Module: HTTPX::Plugins::ResponseCache

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

Overview

This plugin adds support for retrying requests when certain errors happen.

gitlab.com/honeyryderchuck/httpx/wikis/Response-Cache

Defined Under Namespace

Modules: InstanceMethods, OptionsMethods, ResponseMethods Classes: Store

Class Method Summary collapse

Class Method Details

.cacheable_request?(request) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/httpx/plugins/response_cache.rb', line 19

def cacheable_request?(request)
  CACHEABLE_VERBS.include?(request.verb)
end

.cacheable_response?(response) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/httpx/plugins/response_cache.rb', line 23

def cacheable_response?(response)
  response.is_a?(Response) &&
    # partial responses shall not be cached, only full ones.
    response.status != 206 && (
    response.headers.key?("etag") || response.headers.key?("last-modified-at")
  )
end

.cached_response?(response) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/httpx/plugins/response_cache.rb', line 31

def cached_response?(response)
  response.is_a?(Response) && response.status == 304
end

.extra_options(options) ⇒ Object



35
36
37
# File 'lib/httpx/plugins/response_cache.rb', line 35

def extra_options(options)
  options.merge(response_cache_store: Store.new)
end

.load_dependenciesObject



15
16
17
# File 'lib/httpx/plugins/response_cache.rb', line 15

def load_dependencies(*)
  require_relative "response_cache/store"
end