23 #ifndef INCLUDE_API_CACHE_H 24 #define INCLUDE_API_CACHE_H 34 constexpr std::chrono::steady_clock::duration
c_refreshNever = std::chrono::steady_clock::duration::max();
48 std::shared_ptr<APICache> baseCache,
const std::string& subEntry, std::chrono::steady_clock::duration
refresh);
55 APICache(
const std::string& path,
const HueCommandAPI& commands, std::chrono::steady_clock::duration refresh,
56 const nlohmann::json& initial);
75 const nlohmann::json&
getValue()
const;
102 std::shared_ptr<APICache> base;
105 std::chrono::steady_clock::duration refreshDuration;
106 std::chrono::steady_clock::time_point lastRefresh;
107 nlohmann::json value;
Definition: HueCommandAPI.h:37
HueCommandAPI & getCommandAPI()
Get HueCommandAPI used for requests.
Definition: APICache.cpp:127
Namespace for the hueplusplus library.
Definition: Action.h:27
Caches API GET requests and refreshes regularly.
Definition: APICache.h:37
void refresh()
Refresh cache now.
Definition: APICache.cpp:47
APICache(std::shared_ptr< APICache > baseCache, const std::string &subEntry, std::chrono::steady_clock::duration refresh)
Constructs APICache which forwards to a base cache.
Definition: APICache.cpp:29
void setRefreshDuration(std::chrono::steady_clock::duration refreshDuration)
Set duration after which the cache is refreshed.
Definition: APICache.cpp:117
constexpr std::chrono::steady_clock::duration c_refreshNever
Maximum duration, used to indicate that the cache should never be refreshed automatically.
Definition: APICache.h:34
nlohmann::json & getValue()
Get cached value, refresh if necessary.
Definition: APICache.cpp:69
std::string getRequestPath() const
Get path the cache is refreshed from.
Definition: APICache.cpp:166
std::chrono::steady_clock::duration getRefreshDuration() const
Get duration between refreshes.
Definition: APICache.cpp:122