summaryrefslogtreecommitdiffstats
path: root/library/cpp/cache/thread_safe_cache.h
diff options
context:
space:
mode:
Diffstat (limited to 'library/cpp/cache/thread_safe_cache.h')
-rw-r--r--library/cpp/cache/thread_safe_cache.h17
1 files changed, 12 insertions, 5 deletions
diff --git a/library/cpp/cache/thread_safe_cache.h b/library/cpp/cache/thread_safe_cache.h
index b4bd4deedf2..045bea0c8c3 100644
--- a/library/cpp/cache/thread_safe_cache.h
+++ b/library/cpp/cache/thread_safe_cache.h
@@ -52,12 +52,19 @@ namespace NPrivate {
const TPtr GetOrNull(TArgs... args) {
Key key = Callbacks.GetKey(args...);
- TReadGuard r(Mutex);
- auto iter = Cache.Find(key);
- if (iter == Cache.End()) {
- return nullptr;
+ switch (GettersPromotionPolicy) {
+ case EGettersPromotionPolicy::Promoted: {
+ TWriteGuard r(Mutex);
+ if (auto iter = Cache.Find(key); iter != Cache.End())
+ return iter.Value();
+ }
+ case EGettersPromotionPolicy::Unpromoted: {
+ TReadGuard r(Mutex);
+ if (auto iter = Cache.Find(key); iter != Cache.End())
+ return iter.Value();
+ }
}
- return iter.Value();
+ return nullptr;
}
const TPtr Get(TArgs... args) const {