lib/httpx/plugins/response_cache/store.rb in httpx-1.1.2 vs lib/httpx/plugins/response_cache/store.rb in httpx-1.1.3
- old
+ new
@@ -1,19 +1,17 @@
# frozen_string_literal: true
-require "mutex_m"
-
module HTTPX::Plugins
module ResponseCache
class Store
def initialize
@store = {}
- @store.extend(Mutex_m)
+ @store_mutex = Thread::Mutex.new
end
def clear
- @store.synchronize { @store.clear }
+ @store_mutex.synchronize { @store.clear }
end
def lookup(request)
responses = _get(request)
@@ -64,11 +62,11 @@
!original_request.headers.key?(cache_field) || request.headers[cache_field] == original_request.headers[cache_field]
end
end
def _get(request)
- @store.synchronize do
+ @store_mutex.synchronize do
responses = @store[request.response_cache_key]
return unless responses
responses.select! do |res|
@@ -78,10 +76,10 @@
responses
end
end
def _set(request, response)
- @store.synchronize do
+ @store_mutex.synchronize do
responses = (@store[request.response_cache_key] ||= [])
responses.reject! do |res|
res.body.closed? || !res.fresh? || match_by_vary?(request, res)
end