19 #ifndef JAMBA_EXPIRINGDATACACHE_H 20 #define JAMBA_EXPIRINGDATACACHE_H 25 #include <pongasoft/logging/logging.h> 29 using namespace Steinberg;
70 template<
typename T,
typename Ptr = std::shared_ptr<T>,
typename Loader = std::function<Ptr()>>
84 fDataLoader{std::move(iDataLoader)}, fTimeToLiveMilliseconds{iTimeToLiveMilliseconds} {}
88 fDataLoader{iOther.
fDataLoader}, fTimeToLiveMilliseconds{iOther.fTimeToLiveMilliseconds} {}
92 fDataLoader{std::move(iOther.fDataLoader)}, fTimeToLiveMilliseconds{iOther.fTimeToLiveMilliseconds} {}
98 fTimeToLiveMilliseconds = iOther.fTimeToLiveMilliseconds;
99 fCachedData =
nullptr;
108 fDataLoader = std::move(iOther.fDataLoader);
109 fTimeToLiveMilliseconds = iOther.fTimeToLiveMilliseconds;
110 fCachedData =
nullptr;
117 explicit operator bool() const noexcept {
return fDataLoader ? true :
false; }
135 fCachedData = fDataLoader ? fDataLoader() :
nullptr;
147 fCachedData =
nullptr;
152 Loader fDataLoader{};
153 uint32 fTimeToLiveMilliseconds{};
156 std::unique_ptr<AutoReleaseTimer> fTimer{};
161 #endif //JAMBA_EXPIRINGDATACACHE_H Ptr pointer
Definition: ExpiringDataCache.h:75
Loader fDataLoader
Definition: ExpiringDataCache.h:152
T value_type
Definition: ExpiringDataCache.h:74
ExpiringDataCache(Loader iDataLoader, uint32 iTimeToLiveMilliseconds)
Main constructor with loader and TTL.
Definition: ExpiringDataCache.h:83
ExpiringDataCache(ExpiringDataCache const &iOther)
Copy constructor.
Definition: ExpiringDataCache.h:87
Definition: ExpiringDataCache.h:27
Loader loader
Definition: ExpiringDataCache.h:76
void onTimer(Timer *timer) override
Definition: ExpiringDataCache.h:145
Ptr getData()
Main api to retrieve the data.
Definition: ExpiringDataCache.h:126
ExpiringDataCache(ExpiringDataCache &&iOther) noexcept
Move constructor.
Definition: ExpiringDataCache.h:91
The purpose of this class is to implement a short live cache (time to live (or TTL) being a construct...
Definition: ExpiringDataCache.h:71
ExpiringDataCache & operator=(ExpiringDataCache &&iOther) noexcept
Move assignment operator.
Definition: ExpiringDataCache.h:106
static std::unique_ptr< AutoReleaseTimer > create(Steinberg::ITimerCallback *iCallback, Steinberg::uint32 iIntervalMilliseconds)
Creates and return an auto release timer.
Definition: Timer.h:54
ExpiringDataCache & operator=(ExpiringDataCache const &iOther) noexcept
Copy assignment operator.
Definition: ExpiringDataCache.h:95