33 std::optional<State> &cached_state,
34 const std::optional<State> &state,
35 const SerializeFn &serialize_state,
36 const std::string_view serialize_error_message
38 if (cached_state == state) {
43 if (!settings_persistence_api.
clear()) {
47 cached_state = std::nullopt;
52 const auto serialized_state {serialize_state(*state, success)};
54 DD_LOG(error) << serialize_error_message <<
"\n"
59 if (!settings_persistence_api.
store({std::begin(serialized_state), std::end(serialized_state)})) {
63 cached_state = *state;
bool persistState(SettingsPersistenceInterface &settings_persistence_api, std::optional< State > &cached_state, const std::optional< State > &state, const SerializeFn &serialize_state, const std::string_view serialize_error_message)
Persist state and update the cached copy after a successful write.
Definition persistent_state_utils.h:31