25 lines
528 B
C++
25 lines
528 B
C++
#include "Cache.h"
|
|
#include <algorithm>
|
|
#include "mqtt++.h"
|
|
#include <iostream>
|
|
|
|
std::optional<std::string> Cache::cached_topic_value(const std::string& topic) {
|
|
for (const auto& state : m_cache) {
|
|
if (state.topic == topic) {
|
|
return state.value;
|
|
}
|
|
}
|
|
return std::nullopt;
|
|
}
|
|
|
|
TopicState Cache::set_topic_value(const std::string& topic, const std::string& value) {
|
|
for (auto& state : m_cache) {
|
|
if (state.topic == topic) {
|
|
state.value = value;
|
|
|
|
return state;
|
|
}
|
|
}
|
|
|
|
return m_cache.emplace_back(topic, value);
|
|
} |