Module: HTTPX::Plugins::ResponseCache
- Defined in:
- lib/httpx/plugins/response_cache.rb,
lib/httpx/plugins/response_cache/store.rb,
lib/httpx/plugins/response_cache/file_store.rb
Overview
This plugin adds support for retrying requests when certain errors happen.
Defined Under Namespace
Modules: InstanceMethods, OptionsMethods, RequestMethods, ResponseMethods Classes: FileStore, Store
Constant Summary collapse
- SUPPORTED_VARY_HEADERS =
%w[accept accept-encoding accept-language cookie origin].sort.freeze
Class Method Summary collapse
-
.cacheable_response?(response) ⇒ Boolean
whether the
response
can be stored in the response cache. - .extra_options(options) ⇒ Object
- .load_dependencies ⇒ Object
-
.not_modified?(response) ⇒ Boolean
whether the
response
.
Class Method Details
.cacheable_response?(response) ⇒ Boolean
whether the response
can be stored in the response cache. (i.e. has a cacheable body, does not contain directives prohibiting storage, etc…)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/httpx/plugins/response_cache.rb', line 25 def cacheable_response?(response) response.is_a?(Response) && ( response.cache_control.nil? || # TODO: !response.cache_control.include?("private") && is shared cache !response.cache_control.include?("no-store") ) && CACHEABLE_STATUS_CODES.include?(response.status) && # RFC 2616 13.4 - A response received with a status code of 200, 203, 206, 300, 301 or # 410 MAY be stored by a cache and used in reply to a subsequent # request, subject to the expiration mechanism, unless a cache-control # directive prohibits caching. However, a cache that does not support # the Range and Content-Range headers MUST NOT cache 206 (Partial # Content) responses. response.status != 206 end |
.extra_options(options) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/httpx/plugins/response_cache.rb', line 47 def () .merge( supported_vary_headers: SUPPORTED_VARY_HEADERS, response_cache_store: :store, ) end |
.load_dependencies ⇒ Object
18 19 20 21 |
# File 'lib/httpx/plugins/response_cache.rb', line 18 def load_dependencies(*) require_relative "response_cache/store" require_relative "response_cache/file_store" end |
.not_modified?(response) ⇒ Boolean
whether the response
43 44 45 |
# File 'lib/httpx/plugins/response_cache.rb', line 43 def not_modified?(response) response.is_a?(Response) && response.status == 304 end |