mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
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:
parent
aea76a6392
commit
7a19a5da87
1 changed files with 6 additions and 13 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue