Drop StringKeyCache mutex

The StringKeyCache is now only used inside a connection. It's assumed that connections are not used concurrently with multiple queries.
This commit is contained in:
Brian J. Cardiff 2023-12-01 23:55:06 -03:00
parent aea76a6392
commit 7a19a5da87

View file

@ -1,28 +1,21 @@
module DB
class StringKeyCache(T)
@cache = {} of String => T
@mutex = Mutex.new
def fetch(key : String) : T
@mutex.synchronize do
value = @cache.fetch(key, nil)
value = @cache[key] = yield unless value
value
end
value = @cache.fetch(key, nil)
value = @cache[key] = yield unless value
value
end
def each_value
@mutex.synchronize do
@cache.each do |_, value|
yield value
end
@cache.each do |_, value|
yield value
end
end
def clear
@mutex.synchronize do
@cache.clear
end
@cache.clear
end
end
end