Caches API GET requests and refreshes regularly.
More...
#include <hueplusplus/APICache.h>
Caches API GET requests and refreshes regularly.
◆ APICache() [1/2]
hueplusplus::APICache::APICache |
( |
std::shared_ptr< APICache > |
baseCache, |
|
|
const std::string & |
subEntry, |
|
|
std::chrono::steady_clock::duration |
refresh |
|
) |
| |
Constructs APICache which forwards to a base cache.
- Parameters
-
baseCache | Base cache providing a parent state, must not be nullptr |
subEntry | Key of the child to use in the base cache |
refresh | Interval between cache refreshing. May be 0 to always refresh. This is independent from the base cache refresh rate. |
Refreshes only part of the base cache.
◆ APICache() [2/2]
hueplusplus::APICache::APICache |
( |
const std::string & |
path, |
|
|
const HueCommandAPI & |
commands, |
|
|
std::chrono::steady_clock::duration |
refresh, |
|
|
const nlohmann::json & |
initial |
|
) |
| |
Constructs APICache with an own internal json cache.
- Parameters
-
path | URL appended after username, may be empty. |
commands | HueCommandAPI for making API requests. |
refresh | Interval between cache refreshing. May be 0 to always refresh. |
initial | Initial value, may be null. If present, assumes the value is up to date. |
◆ getCommandAPI() [1/2]
◆ getCommandAPI() [2/2]
const HueCommandAPI & hueplusplus::APICache::getCommandAPI |
( |
| ) |
const |
◆ getRefreshDuration()
std::chrono::steady_clock::duration hueplusplus::APICache::getRefreshDuration |
( |
| ) |
const |
Get duration between refreshes.
◆ getRequestPath()
std::string hueplusplus::APICache::getRequestPath |
( |
| ) |
const |
◆ getValue() [1/2]
nlohmann::json & hueplusplus::APICache::getValue |
( |
| ) |
|
Get cached value, refresh if necessary.
- Exceptions
-
std::system_error | when system or socket operations fail |
HueException | when response contained no body |
HueAPIResponseException | when response contains an error |
nlohmann::json::parse_error | when response could not be parsed |
◆ getValue() [2/2]
const nlohmann::json & hueplusplus::APICache::getValue |
( |
| ) |
const |
Get cached value, does not refresh.
- Exceptions
-
◆ refresh()
void hueplusplus::APICache::refresh |
( |
| ) |
|
Refresh cache now.
- Exceptions
-
std::system_error | when system or socket operations fail |
HueException | when response contained no body |
HueAPIResponseException | when response contains an error |
nlohmann::json::parse_error | when response could not be parsed |
If there is a base cache, refreshes only the used part of that cache.
◆ setRefreshDuration()
void hueplusplus::APICache::setRefreshDuration |
( |
std::chrono::steady_clock::duration |
refreshDuration | ) |
|
Set duration after which the cache is refreshed.
- Parameters
-
refreshDuration | Interval between cache refreshing. May be 0 to always refresh, or c_refreshNever to never refresh. |
If the new refresh duration is exceeded, does not refresh immediately. Instead, the next non-const getValue() call will refresh the value. This is to reduce the number of unneccessary requests.
The documentation for this class was generated from the following files: