summaryrefslogtreecommitdiff
path: root/src/cache.cpp
diff options
context:
space:
mode:
authorCedric Nugteren <web@cedricnugteren.nl>2017-02-11 14:05:38 +0100
committerCedric Nugteren <web@cedricnugteren.nl>2017-02-11 14:05:38 +0100
commit36b942a6982578af33ca26a5306ebd7012f2329b (patch)
tree33457580ea08116d4a105a728eba44d96ed087da /src/cache.cpp
parentdc93523204ebe8562145997673f25f8e59f9d2f5 (diff)
Added an option to remove items from the caches, optionally by a subset of 2 specific key-values only
Diffstat (limited to 'src/cache.cpp')
-rw-r--r--src/cache.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/cache.cpp b/src/cache.cpp
index c5cc6a4d..c7b4792e 100644
--- a/src/cache.cpp
+++ b/src/cache.cpp
@@ -65,6 +65,37 @@ void Cache<Key, Value>::Store(Key &&key, Value &&value) {
}
template <typename Key, typename Value>
+void Cache<Key, Value>::Remove(const Key &key) {
+ std::lock_guard<std::mutex> lock(cache_mutex_);
+#if __cplusplus >= 201402L
+ cache_.erase(key);
+#else
+ auto it = cache_.begin();
+ while (it != cache_.end()) {
+ if ((*it).first == key) {
+ it = cache_.erase(it);
+ }
+ else ++it;
+ }
+#endif
+}
+
+template <typename Key, typename Value>
+template <int I1, int I2>
+void Cache<Key, Value>::RemoveBySubset(const Key key) {
+ std::lock_guard<std::mutex> lock(cache_mutex_);
+ auto it = cache_.begin();
+ while (it != cache_.end()) {
+ const auto current_key = (*it).first;
+ if ((std::get<I1>(key) == std::get<I1>(current_key)) &&
+ (std::get<I2>(key) == std::get<I2>(current_key))) {
+ it = cache_.erase(it);
+ }
+ else ++it;
+ }
+}
+
+template <typename Key, typename Value>
void Cache<Key, Value>::Invalidate() {
std::lock_guard<std::mutex> lock(cache_mutex_);
@@ -88,6 +119,7 @@ template std::string BinaryCache::Get(const BinaryKeyRef &, bool *) const;
template class Cache<ProgramKey, Program>;
template Program ProgramCache::Get(const ProgramKeyRef &, bool *) const;
+template void ProgramCache::RemoveBySubset<1, 2>(const ProgramKey); // by precision and routine name
// =================================================================================================