Skip to content

Commit

Permalink
rename dt to cacheperiod and make supplier const
Browse files Browse the repository at this point in the history
  • Loading branch information
spacey-sooty committed Mar 2, 2024
1 parent 1034655 commit c0b7c2d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions wombat/src/main/cpp/utils/Cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

template <typename T>
wom::utils::Cached<T>::Cached(std::function<T()> supplier)
: m_supplier{supplier}, k_timestamp{wom::utils::now()}, k_dt{20_ms} {};
: m_supplier{supplier}, k_timestamp{wom::utils::now()}, k_cacheperiod{20_ms} {};

template <typename T>
wom::utils::Cached<T>::Cached(std::function<T()> supplier, units::second_t dt)
: m_supplier{supplier}, k_timestamp{wom::utils::now()}, k_dt{dt} {};
wom::utils::Cached<T>::Cached(std::function<T()> supplier, units::second_t cacheperiod)
: m_supplier{supplier}, k_timestamp{wom::utils::now()}, k_cacheperiod{cacheperiod} {};

template <typename T>
wom::utils::Cached<T>& wom::utils::Cached<T>::Update() {
Expand All @@ -27,5 +27,5 @@ T& wom::utils::Cached<T>::GetValue() {

template <typename T>
bool wom::utils::Cached<T>::IsStale() {
return wom::utils::now() - this->k_timestamp > k_dt;
return wom::utils::now() - this->k_timestamp > k_cacheperiod;
}
8 changes: 4 additions & 4 deletions wombat/src/main/include/utils/Cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class Cached {
* Creates a new Cached<T> with the given supplier.
*
* @param supplier A function that sources the value.
* @param dt The validity length of the stored value.
* @param cacheperiod The validity length of the stored value.
*/
Cached(std::function<T()> supplier, units::second_t dt);
Cached(std::function<T()> supplier, units::second_t cacheperiod);

Cached(Cached&&) = default;
Cached& operator=(Cached&&) = default;
Expand All @@ -48,9 +48,9 @@ class Cached {

private:
T& m_value;
std::function<T()> m_supplier;
const std::function<T()> m_supplier;
const units::second_t k_timestamp;
const units::second_t k_dt;
const units::second_t k_cacheperiod;
};

} // namespace utils
Expand Down

0 comments on commit c0b7c2d

Please sign in to comment.