From d7e11e644ced5f70458f690a4acfed5d29971200 Mon Sep 17 00:00:00 2001
From: EndrII <EndrIIMail@gmail.com>
Date: Thu, 18 Nov 2021 15:01:53 +0300
Subject: [PATCH] added cahce tot settings class

---
 isettings.cpp | 14 ++++++++++++--
 isettings.h   |  3 +++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/isettings.cpp b/isettings.cpp
index 02658e6..78c70e9 100644
--- a/isettings.cpp
+++ b/isettings.cpp
@@ -30,7 +30,12 @@ ISettings *ISettings::instance(){
 }
 
 QVariant ISettings::getValue(const QString &key, const QVariant &def) {
-    return getValueImplementation(key, def);
+
+    if (!_cache.contains(key)) {
+        _cache[key] = getValueImplementation(key, def);
+    }
+
+    return _cache.value(key, def);
 }
 
 QString ISettings::getStrValue(const QString &key, const QString &def) {
@@ -38,11 +43,16 @@ QString ISettings::getStrValue(const QString &key, const QString &def) {
 }
 
 void ISettings::sync() {
+    for (auto it = _cache.begin(); it != _cache.end(); ++it) {
+        setValueImplementation(it.key(), it.value());
+    }
+
     return syncImplementation();
 }
 
 void ISettings::setValue(const QString key, const QVariant &value) {
-    return setValueImplementation(key, value);
+
+    _cache[key] = value;
 
     emit valueChanged(key, value);
     emit valueStrChanged(key, value.toString());
diff --git a/isettings.h b/isettings.h
index 869fd10..f2cfd82 100644
--- a/isettings.h
+++ b/isettings.h
@@ -153,6 +153,9 @@ protected:
 
 private:
     SettingsSaveMode _mode = SettingsSaveMode::Auto;
+
+    QHash<QString, QVariant> _cache;
+
     static ISettings* _settings;
 };
 } ;