From 121e3c7b8f9ab8ac41eb7ee82b96b04f88d6a7ae Mon Sep 17 00:00:00 2001 From: Vlad Zolotarov Date: Wed, 12 Jul 2017 18:16:02 -0400 Subject: [PATCH 1/2] utils::loading_cache: make a timer use a loading_cache_clock_type clock as a source Signed-off-by: Vlad Zolotarov --- utils/loading_cache.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/loading_cache.hh b/utils/loading_cache.hh index ddf78436df..61d929d9d1 100644 --- a/utils/loading_cache.hh +++ b/utils/loading_cache.hh @@ -378,7 +378,7 @@ private: std::chrono::milliseconds _refresh; logging::logger& _logger; std::function(const Key&)> _load; - timer _timer; + timer _timer; }; } From 76ea74f3fd259c63b0bc8ddacbac5ba52dd0c941 Mon Sep 17 00:00:00 2001 From: Vlad Zolotarov Date: Wed, 12 Jul 2017 18:21:02 -0400 Subject: [PATCH 2/2] utils::loading_cache: arm the timer with a period equal to min(_expire, _update) Arm the timer with a period that is not greater than either the permissions_validity_in_ms or the permissions_update_interval_in_ms in order to ensure that we are not stuck with the values older than permissions_validity_in_ms. Fixes #2590 Signed-off-by: Vlad Zolotarov --- utils/loading_cache.hh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/utils/loading_cache.hh b/utils/loading_cache.hh index 61d929d9d1..a5bf727b81 100644 --- a/utils/loading_cache.hh +++ b/utils/loading_cache.hh @@ -182,8 +182,9 @@ public: throw exceptions::configuration_exception("loading_cache: caching is enabled but refresh period and/or max_size are zero"); } + _timer_period = std::min(_expiry, _refresh); _timer.set_callback([this] { on_timer(); }); - _timer.arm(_refresh); + _timer.arm(_timer_period); } ~loading_cache() { @@ -364,7 +365,7 @@ private: return now(); }).finally([this, timer_start_tp] { _logger.trace("on_timer(): rearming"); - _timer.arm(timer_start_tp + _refresh); + _timer.arm(timer_start_tp + _timer_period); }); } @@ -376,6 +377,7 @@ private: size_t _max_size; std::chrono::milliseconds _expiry; std::chrono::milliseconds _refresh; + loading_cache_clock_type::duration _timer_period; logging::logger& _logger; std::function(const Key&)> _load; timer _timer;