Public Class methods
new()
[show source]
# File lib/httpx/plugins/response_cache/store.rb 6 def initialize 7 @store = {} 8 @store_mutex = Thread::Mutex.new 9 end
Public Instance methods
cache(request, response)
[show source]
# File lib/httpx/plugins/response_cache/store.rb 27 def cache(request, response) 28 return unless ResponseCache.cacheable_request?(request) && ResponseCache.cacheable_response?(response) 29 30 _set(request, response) 31 end
cached?(request)
[show source]
# File lib/httpx/plugins/response_cache/store.rb 23 def cached?(request) 24 lookup(request) 25 end
clear()
[show source]
# File lib/httpx/plugins/response_cache/store.rb 11 def clear 12 @store_mutex.synchronize { @store.clear } 13 end
lookup(request)
[show source]
# File lib/httpx/plugins/response_cache/store.rb 15 def lookup(request) 16 responses = _get(request) 17 18 return unless responses 19 20 responses.find(&method(:match_by_vary?).curry(2)[request]) 21 end
prepare(request)
[show source]
# File lib/httpx/plugins/response_cache/store.rb 33 def prepare(request) 34 cached_response = lookup(request) 35 36 return unless cached_response 37 38 return unless match_by_vary?(request, cached_response) 39 40 if !request.headers.key?("if-modified-since") && (last_modified = cached_response.headers["last-modified"]) 41 request.headers.add("if-modified-since", last_modified) 42 end 43 44 if !request.headers.key?("if-none-match") && (etag = cached_response.headers["etag"]) # rubocop:disable Style/GuardClause 45 request.headers.add("if-none-match", etag) 46 end 47 end