diff options
| author | dskor <[email protected]> | 2025-10-16 01:40:10 +0300 |
|---|---|---|
| committer | dskor <[email protected]> | 2025-10-16 02:22:15 +0300 |
| commit | 8d275bde2bd67470dccbba997208810b4280d8f0 (patch) | |
| tree | a8fdd96862e2f9ee45f76dd059714983f1ae55b3 /library/cpp/cache/thread_safe_cache.h | |
| parent | 52bb9813716cd4308702d44d69fb3a448500f50f (diff) | |
TWriteGuard on GetOrNull for ThreadSaveCache with promotion
Find может делать Promote, который мутирует List ( LRUList например: <https://nda.ya.ru/t/fFSNn0ML7LRudF> )
commit_hash:dca1db67d45c7faca51cc1251cbe155c7857e362
Diffstat (limited to 'library/cpp/cache/thread_safe_cache.h')
| -rw-r--r-- | library/cpp/cache/thread_safe_cache.h | 17 |
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 { |
