Manages a cache of WeatherData
with an automatic timeout mechanism.
More...
#include <QueryCached.h>
Signals | |
void | weatherCacheOutdated () |
Signal emitted when the cached weather data becomes outdated. | |
Public Member Functions | |
QueryCached (QObject *parent=nullptr) | |
Constructs a QueryCached object. | |
void | setTimeoutInterval (int interval) |
Sets the timeout interval for the cached data. | |
void | installWeatherData (const WeatherData &data) |
Installs new WeatherData into the cache. | |
std::optional< WeatherData > | requestWeatherData () |
Requests the cached WeatherData . | |
Manages a cache of WeatherData
with an automatic timeout mechanism.
This class provides a simple caching mechanism for WeatherData
. It allows storing data and retrieving it, but the cached data becomes "outdated" after a specified timeout interval. When the cache is outdated, it indicates that fresh data should be fetched. It uses a QTimer
to manage the timeout.
|
explicit |
Constructs a QueryCached object.
parent | A pointer to the parent QObject, allowing for proper object hierarchy and memory management. Defaults to nullptr. |
void QueryCached::installWeatherData | ( | const WeatherData & | data | ) |
Installs new WeatherData
into the cache.
data | A constant reference to the WeatherData to be cached. |
std::optional< WeatherData > QueryCached::requestWeatherData | ( | ) |
Requests the cached WeatherData
.
std::nullopt
is returned, and the weatherCacheOutdated
signal is emitted. std::optional<WeatherData>
containing the cached data if valid, otherwise std::nullopt
. void QueryCached::setTimeoutInterval | ( | int | interval | ) |
Sets the timeout interval for the cached data.
installWeatherData
call, the cached data will be considered outdated. interval | The timeout interval in milliseconds. |
|
signal |
Signal emitted when the cached weather data becomes outdated.