From f0fe66c675b94b17a5671615445658e6b936c003 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Fri, 26 Jun 2020 18:30:37 +0200 Subject: [PATCH] max_size guaranteed --- passphrase_cache.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/passphrase_cache.cc b/passphrase_cache.cc index 196a352..6b372bf 100644 --- a/passphrase_cache.cc +++ b/passphrase_cache.cc @@ -4,6 +4,8 @@ namespace pEp { void PassphraseCache::add(std::string passphrase) { std::lock_guard lock(_mtx); + while (_cache.size() >= _max_size) + _cache.pop_front(); _cache.push_back({passphrase, clock::now()}); } @@ -26,8 +28,6 @@ namespace pEp { { while (!_cache.empty() && _cache.front().tp < clock::now() - _timeout) _cache.pop_front(); - while (_cache.size() > _max_size) - _cache.pop_front(); } void PassphraseCache::refresh(cache::iterator entry)