Browse Source

support max_size

synchronous
Volker Birk 5 years ago
parent
commit
24925a3b1c
  1. 2
      passphrase_cache.cc
  2. 5
      passphrase_cache.hh
  3. 3
      test/test_passphrase_cache.cc

2
passphrase_cache.cc

@ -24,6 +24,8 @@ namespace pEp {
{
while (!_cache.empty() && _cache.front().tp < clock::now() - _timeout)
_cache.pop_front();
while (_cache.size() > _max_size)
_cache.pop_front();
}
};

5
passphrase_cache.hh

@ -19,11 +19,12 @@ namespace pEp {
std::list<cache_entry> _cache;
std::mutex _mtx;
int _max_size;
duration _timeout;
public:
PassphraseCache(duration timeout = std::chrono::minutes(10)) :
_timeout(timeout) { }
PassphraseCache(int max_size=20, duration timeout = std::chrono::minutes(10)) :
_max_size(max_size), _timeout(timeout) { }
~PassphraseCache() { }
PassphraseCache(const PassphraseCache& second) :
_cache(second._cache), _timeout(second._timeout) { }

3
test/test_passphrase_cache.cc

@ -6,7 +6,8 @@
int main()
{
pEp::PassphraseCache cache{std::chrono::seconds(1)};
pEp::PassphraseCache cache{2, std::chrono::seconds(1)};
cache.add("say");
cache.add("hello");
cache.add("world");

Loading…
Cancel
Save