diff --git a/src/tech/include/cachedresult.hpp b/src/tech/include/cachedresult.hpp index ba2cbfe6..add13030 100644 --- a/src/tech/include/cachedresult.hpp +++ b/src/tech/include/cachedresult.hpp @@ -113,7 +113,8 @@ class CachedResultWithArgs : public CachedResultBase TKey key(std::forward(funcArgs)...); auto [it, isInserted] = _data.try_emplace(key, flattenTuple, key, nowTime); if (!isInserted && this->_state != State::kForceCache && - this->_refreshPeriod < nowTime - it->second.lastUpdatedTs) { + // less or equal to make sure value is always refreshed for a zero refresh period + this->_refreshPeriod <= nowTime - it->second.lastUpdatedTs) { it->second = Value(flattenTuple, std::move(key), nowTime); } return it->second.result; diff --git a/src/tech/test/cachedresult_test.cpp b/src/tech/test/cachedresult_test.cpp index d60436c0..2329b700 100644 --- a/src/tech/test/cachedresult_test.cpp +++ b/src/tech/test/cachedresult_test.cpp @@ -103,7 +103,7 @@ TEST_F(CachedResultTest, SetInCache) { cachedResult.set(42, nowTime, 3, 4); // timestamp too old, should not be set EXPECT_EQ(cachedResult.get(3, 4), 7); - cachedResult.set(42, nowTime + 2 * kCacheExpireTime, 3, 4); // should be set + cachedResult.set(42, SteadyClock::now(), 3, 4); // should be set EXPECT_EQ(cachedResult.get(3, 4), 42); }