Module: HTTPX::Plugins::ResponseCache::InstanceMethods
- Defined in:
- lib/httpx/plugins/response_cache.rb
Instance Method Summary collapse
Instance Method Details
#build_request ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/httpx/plugins/response_cache.rb', line 53 def build_request(*) request = super return request unless ResponseCache.cacheable_request?(request) && @options.response_cache_store.cached?(request.uri) @options.response_cache_store.prepare(request) request end |
#clear_response_cache ⇒ Object
49 50 51 |
# File 'lib/httpx/plugins/response_cache.rb', line 49 def clear_response_cache @options.response_cache_store.clear end |
#fetch_response(request) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/httpx/plugins/response_cache.rb', line 62 def fetch_response(request, *) response = super if response && ResponseCache.cached_response?(response) log { "returning cached response for #{request.uri}" } cached_response = @options.response_cache_store.lookup(request.uri) response.copy_from_cached(cached_response) end @options.response_cache_store.cache(request.uri, response) if response && ResponseCache.cacheable_response?(response) response end |