diff options
| author | Varun Ravichandran <varun.ravichandran@mongodb.com> | 2021-09-16 21:04:36 +0000 |
|---|---|---|
| committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-10-01 14:56:46 +0000 |
| commit | fc05532015895c8907437ea0c06fe83ab6c6f1dc (patch) | |
| tree | 07829e19f6de8088e44f1b75a942944100f8be55 /src/mongo/util/invalidating_lru_cache.h | |
| parent | 55a9a92bce2fe94ef3efe42123fa31617f3d5fcc (diff) | |
| download | mongo-fc05532015895c8907437ea0c06fe83ab6c6f1dc.tar.gz | |
SERVER-59148: Periodically refresh LDAP users in authorization user cache
Diffstat (limited to 'src/mongo/util/invalidating_lru_cache.h')
| -rw-r--r-- | src/mongo/util/invalidating_lru_cache.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/mongo/util/invalidating_lru_cache.h b/src/mongo/util/invalidating_lru_cache.h index f2307dc007f..d07eb12e0ec 100644 --- a/src/mongo/util/invalidating_lru_cache.h +++ b/src/mongo/util/invalidating_lru_cache.h @@ -535,6 +535,32 @@ public: } } + /** + * Returns a vector of ValueHandles for all of the entries that satisfy matchPredicate. + */ + template <typename Pred> + std::vector<ValueHandle> getEntriesIf(Pred matchPredicate) { + std::vector<ValueHandle> entries; + entries.reserve(_cache.size() + _evictedCheckedOutValues.size()); + { + stdx::lock_guard lg(_mutex); + for (const auto& entry : _cache) { + if (matchPredicate(entry.first, &entry.second->value)) { + entries.push_back(ValueHandle(entry.second)); + } + } + + for (const auto& entry : _evictedCheckedOutValues) { + if (auto storedValue = entry.second.lock()) { + if (matchPredicate(entry.first, &storedValue->value)) { + entries.push_back(ValueHandle(std::move(storedValue))); + } + } + } + } + return entries; + } + struct CachedItemInfo { Key key; // The key of the item in the cache long int useCount; // The number of callers of 'get', which still have the item checked-out |
