From 4370a51e221b55baf3a0c05fa42ec3a317e9d433 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Sun, 10 Mar 2024 23:08:07 -0500 Subject: [PATCH] policy_cache.hpp --- src/policy_cache.hpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/policy_cache.hpp b/src/policy_cache.hpp index 3c7bc900..1846005e 100644 --- a/src/policy_cache.hpp +++ b/src/policy_cache.hpp @@ -44,14 +44,19 @@ public: std::string const &val_) { auto size = _cache.size(); - - _cache.visit_while([&](Map::value_type const &v_) - { - // _cache.erase(v_.first); - --size; - fmt::print("{} > {}\n",size,_max_size); - return (size > _max_size); - }); + + while(_cache.size() > _max_size) + { + std::string key; + _cache.visit_while([&](Map::value_type const &v_) + { + key = v_.first; + return false; + }); + + _cache.erase(key); + fmt::print("{} > {} - {}\n",_cache.size(),_max_size,key); + } _cache.insert_or_assign(key_,val_); }