add AbstractCache::forEach()

This commit is contained in:
Günter Obiltschnig
2021-04-11 15:55:47 +02:00
parent d126e51ec3
commit 8625b29f9f
3 changed files with 42 additions and 0 deletions

View File

@@ -176,6 +176,23 @@ public:
return result;
}
template <typename Fn>
void forEach(Fn&& fn) const
/// Iterates over all key-value pairs in the
/// cache, using a functor or lambda expression.
///
/// The given functor must take the key and value
/// as parameters. Note that the value is passed
/// as the actual value (or reference),
/// not a Poco::SharedPtr.
{
typename TMutex::ScopedLock lock(_mutex);
for (const auto& p: _data)
{
fn(p.first, *p.second);
}
}
protected:
mutable FIFOEvent<ValidArgs<TKey>> IsValid;
mutable FIFOEvent<KeySet> Replace;