This plugin caches and reuses responses based on HTTP caching directives defined by the [HTTP Caching RFC](www.rfc-editor.org/rfc/rfc9111.html)
Classes and Modules
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 ) 51 end
load_dependencies(klass)
[show source]
# File lib/httpx/plugins/response_cache.rb 19 def load_dependencies(klass) 20 klass.plugin(:cache) 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