/** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ #pragma once #include #include #include namespace Aws { namespace Utils { template class ConcurrentCache { public: explicit ConcurrentCache(size_t size = 1000) : m_cache(size) { } bool Get(const TKey& key, TValue& value) const { Aws::Utils::Threading::ReaderLockGuard g(m_rwlock); return m_cache.Get(key, value); } template void Put(const TKey& key, UValue&& val, std::chrono::milliseconds duration) { Aws::Utils::Threading::WriterLockGuard g(m_rwlock); m_cache.Put(key, std::forward(val), duration); } template void Put(TKey&& key, UValue&& val, std::chrono::milliseconds duration) { Aws::Utils::Threading::WriterLockGuard g(m_rwlock); m_cache.Put(std::move(key), std::forward(val), duration); } private: Aws::Utils::Cache m_cache; mutable Aws::Utils::Threading::ReaderWriterLock m_rwlock; }; } }