mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
c106775ea9
* Add pool_concurrency_test manual spec Add MT connection count without Mutex * Drop checkout_some, simpler pool_prepared statement * Make pool statement a struct * Drop StringKeyCache mutex The StringKeyCache is now only used inside a connection. It's assumed that connections are not used concurrently with multiple queries. * Drop do_close in pool statements * Add specs and update comment * Fix typo
21 lines
346 B
Crystal
21 lines
346 B
Crystal
module DB
|
|
class StringKeyCache(T)
|
|
@cache = {} of String => T
|
|
|
|
def fetch(key : String) : T
|
|
value = @cache.fetch(key, nil)
|
|
value = @cache[key] = yield unless value
|
|
value
|
|
end
|
|
|
|
def each_value
|
|
@cache.each do |_, value|
|
|
yield value
|
|
end
|
|
end
|
|
|
|
def clear
|
|
@cache.clear
|
|
end
|
|
end
|
|
end
|