~aleteoryx/muditaos

ref: 00fde83a0a595847c500608054fbc375d93ca5ac muditaos/module-services/service-db/agents/settings/SettingsCache.cpp -rw-r--r-- 759 bytes
00fde83a — RobertPiet [EGD-5808] Introduce cache for Settings 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <service-db/SettingsCache.hpp>
#include <mutex.hpp>

namespace settings
{

    SettingsCache *SettingsCache::getInstance()
    {
        static SettingsCache instance;
        return &instance;
    }

    const std::string &SettingsCache::getValue(const EntryPath &path) const
    {
        static const std::string empty = "";
        cpp_freertos::LockGuard lock(settingsMutex);
        auto pathIt = settingsMap.find(path);
        if (settingsMap.end() != pathIt) {
            return pathIt->second;
        }
        return empty;
    }

    void SettingsCache::setValue(const EntryPath &path, const std::string &value)
    {
        cpp_freertos::LockGuard lock(settingsMutex);
        settingsMap[path] = value;
    }
} // namespace settings