module HTTPX::Plugins::ResponseCache

  1. lib/httpx/plugins/response_cache.rb
  2. lib/httpx/plugins/response_cache/file_store.rb
  3. lib/httpx/plugins/response_cache/store.rb
  4. show all

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

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

Constants

SUPPORTED_VARY_HEADERS = %w[accept accept-encoding accept-language cookie origin].sort.freeze  

Public Class methods

cacheable_response?(response)

whether the response can be stored in the response cache. (i.e. has a cacheable body, does not contain directives prohibiting storage, etc…)

[show source]
   # File lib/httpx/plugins/response_cache.rb
25 def cacheable_response?(response)
26   response.is_a?(Response) &&
27     (
28       response.cache_control.nil? ||
29       # TODO: !response.cache_control.include?("private") && is shared cache
30       !response.cache_control.include?("no-store")
31     ) &&
32     CACHEABLE_STATUS_CODES.include?(response.status) &&
33     # RFC 2616 13.4 - A response received with a status code of 200, 203, 206, 300, 301 or
34     # 410 MAY be stored by a cache and used in reply to a subsequent
35     # request, subject to the expiration mechanism, unless a cache-control
36     # directive prohibits caching. However, a cache that does not support
37     # the Range and Content-Range headers MUST NOT cache 206 (Partial
38     # Content) responses.
39     response.status != 206
40 end
extra_options(options)
[show source]
   # File lib/httpx/plugins/response_cache.rb
47 def extra_options(options)
48   options.merge(
49     supported_vary_headers: SUPPORTED_VARY_HEADERS,
50     response_cache_store: :store,
51   )
52 end
load_dependencies(*)
[show source]
   # File lib/httpx/plugins/response_cache.rb
18 def load_dependencies(*)
19   require_relative "response_cache/store"
20   require_relative "response_cache/file_store"
21 end
not_modified?(response)

whether the response

[show source]
   # File lib/httpx/plugins/response_cache.rb
43 def not_modified?(response)
44   response.is_a?(Response) && response.status == 304
45 end