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
|
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
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue