hueplusplus 1.2.0
Loading...
Searching...
No Matches
APICache.h
Go to the documentation of this file.
1
23#ifndef INCLUDE_API_CACHE_H
24#define INCLUDE_API_CACHE_H
25
26#include <chrono>
27#include <string>
28
29#include "HueCommandAPI.h"
30
31namespace hueplusplus
32{
34constexpr std::chrono::steady_clock::duration c_refreshNever = std::chrono::steady_clock::duration::max();
35
38{
39public:
48 std::shared_ptr<APICache> baseCache, const std::string& subEntry, std::chrono::steady_clock::duration refresh);
49
55 APICache(const std::string& path, const HueCommandAPI& commands, std::chrono::steady_clock::duration refresh,
56 const nlohmann::json& initial);
57
65 void refresh();
66
72 nlohmann::json& getValue();
75 const nlohmann::json& getValue() const;
76
84 void setRefreshDuration(std::chrono::steady_clock::duration refreshDuration);
85
87 std::chrono::steady_clock::duration getRefreshDuration() const;
88
92 const HueCommandAPI& getCommandAPI() const;
93
96 std::string getRequestPath() const;
97
98private:
99 bool needsRefresh();
100
101private:
102 std::shared_ptr<APICache> base;
103 std::string path;
104 HueCommandAPI commands;
105 std::chrono::steady_clock::duration refreshDuration;
106 std::chrono::steady_clock::time_point lastRefresh;
107 nlohmann::json value;
108};
109} // namespace hueplusplus
110
111#endif
Caches API GET requests and refreshes regularly.
Definition APICache.h:38
std::chrono::steady_clock::duration getRefreshDuration() const
Get duration between refreshes.
Definition APICache.cpp:122
void setRefreshDuration(std::chrono::steady_clock::duration refreshDuration)
Set duration after which the cache is refreshed.
Definition APICache.cpp:117
void refresh()
Refresh cache now.
Definition APICache.cpp:47
std::string getRequestPath() const
Get path the cache is refreshed from.
Definition APICache.cpp:166
HueCommandAPI & getCommandAPI()
Get HueCommandAPI used for requests.
Definition APICache.cpp:127
nlohmann::json & getValue()
Get cached value, refresh if necessary.
Definition APICache.cpp:69
Definition HueCommandAPI.h:38
Namespace for the hueplusplus library.
Definition Action.h:28
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