CCIMXDesktop
 
Loading...
Searching...
No Matches
QueryCached Class Reference

Manages a cache of WeatherData with an automatic timeout mechanism. More...

#include <QueryCached.h>

Inheritance diagram for QueryCached:

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< WeatherDatarequestWeatherData ()
 Requests the cached WeatherData.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ QueryCached()

QueryCached::QueryCached ( QObject *  parent = nullptr)
explicit

Constructs a QueryCached object.

Parameters
parentA pointer to the parent QObject, allowing for proper object hierarchy and memory management. Defaults to nullptr.

Member Function Documentation

◆ installWeatherData()

void QueryCached::installWeatherData ( const WeatherData data)

Installs new WeatherData into the cache.

  • When new data is installed, the cache is marked as fresh, and the timeout timer is restarted.
    Parameters
    dataA constant reference to the WeatherData to be cached.

◆ requestWeatherData()

std::optional< WeatherData > QueryCached::requestWeatherData ( )

Requests the cached WeatherData.

  • If the cached data is valid and not outdated, it is returned. If the cache is outdated, std::nullopt is returned, and the weatherCacheOutdated signal is emitted.
    Returns
    An std::optional<WeatherData> containing the cached data if valid, otherwise std::nullopt.

◆ setTimeoutInterval()

void QueryCached::setTimeoutInterval ( int  interval)

Sets the timeout interval for the cached data.

  • After this interval (in milliseconds) passes since the last installWeatherData call, the cached data will be considered outdated.
    Parameters
    intervalThe timeout interval in milliseconds.

◆ weatherCacheOutdated

void QueryCached::weatherCacheOutdated ( )
signal

Signal emitted when the cached weather data becomes outdated.

  • This signal indicates that a fresh fetch of weather data is required.

The documentation for this class was generated from the following files: