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