Caches: method to save values given a list of keys.

This commit is contained in:
Mathew Sutcliffe
2016-06-30 22:20:32 +01:00
parent 242e041ceb
commit 843620ca3c
4 changed files with 50 additions and 0 deletions

View File

@@ -181,6 +181,18 @@ namespace BlackMisc
return map;
}
CVariantMap CValueCache::getAllValues(const QStringList &keys) const
{
QMutexLocker lock(&m_mutex);
CVariantMap map;
for (const auto &key : keys)
{
auto it = m_elements.constFind(key);
if (it != m_elements.cend()) { map.insert(key, (*it)->m_value); }
}
return map;
}
CValueCachePacket CValueCache::getAllValuesWithTimestamps(const QString &keyPrefix) const
{
QMutexLocker lock(&m_mutex);
@@ -299,6 +311,15 @@ namespace BlackMisc
return status;
}
CStatusMessage CValueCache::saveToFiles(const QString &dir, const QStringList &keys)
{
QMutexLocker lock(&m_mutex);
auto values = getAllValues(keys);
auto status = saveToFiles(dir, values);
if (status.isSuccess()) { markAllAsSaved(keys); }
return status;
}
CStatusMessage CValueCache::saveToFiles(const QString &dir, const CVariantMap &values, const QString &keysMessage) const
{
QMap<QString, CVariantMap> namespaces;
@@ -398,6 +419,15 @@ namespace BlackMisc
}
}
void CValueCache::markAllAsSaved(const QStringList &keys)
{
QMutexLocker lock(&m_mutex);
for (const auto &key : keys)
{
getElement(key).m_saved = true;
}
}
QString CValueCache::filenameForKey(const QString &key)
{
return key.section('/', 0, 0) + ".json";