mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 02:35:33 +08:00
refs #581 Allow setting the timestamp when putting a value in the cache.
This commit is contained in:
@@ -178,7 +178,7 @@ namespace BlackMisc
|
||||
QString getFilename() const { return CDataCache::filenameForKey(this->getKey()); }
|
||||
|
||||
//! Data cache doesn't support setAndSave (because set() already causes save anyway).
|
||||
CStatusMessage setAndSave(const typename Trait::type &value) = delete;
|
||||
CStatusMessage setAndSave(const typename Trait::type &value, qint64 timestamp = 0) = delete;
|
||||
};
|
||||
|
||||
/*!
|
||||
|
||||
@@ -410,11 +410,12 @@ namespace BlackMisc
|
||||
return element.m_value.read();
|
||||
}
|
||||
|
||||
CStatusMessage CValuePage::setValue(Element &element, const CVariant &value, bool save)
|
||||
CStatusMessage CValuePage::setValue(Element &element, const CVariant &value, qint64 timestamp, bool save)
|
||||
{
|
||||
Q_ASSERT(QThread::currentThread() == thread());
|
||||
|
||||
if (element.m_value.read() == value) { return {}; }
|
||||
if (timestamp == 0) { timestamp = QDateTime::currentMSecsSinceEpoch(); }
|
||||
if (element.m_value.read() == value && element.m_timestamp == timestamp) { return {}; }
|
||||
|
||||
auto error = validate(element, value);
|
||||
if (error.isEmpty())
|
||||
@@ -430,7 +431,7 @@ namespace BlackMisc
|
||||
element.m_saved = save;
|
||||
|
||||
element.m_value.uniqueWrite() = value;
|
||||
emit valuesWantToCache({ { { element.m_key, value } }, QDateTime::currentMSecsSinceEpoch(), save });
|
||||
emit valuesWantToCache({ { { element.m_key, value } }, timestamp, save });
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -279,10 +279,10 @@ namespace BlackMisc
|
||||
const T &get() const { static const T empty {}; return *(isValid() ? static_cast<const T *>(getVariant().data()) : &empty); }
|
||||
|
||||
//! Write a new value. Must be called from the thread in which the owner lives.
|
||||
CStatusMessage set(const T &value) { return m_page.setValue(m_element, CVariant::from(value)); }
|
||||
CStatusMessage set(const T &value, qint64 timestamp = 0) { return m_page.setValue(m_element, CVariant::from(value), timestamp); }
|
||||
|
||||
//! Write and save in the same step. Must be called from the thread in which the owner lives.
|
||||
CStatusMessage setAndSave(const T &value) { return m_page.setValue(m_element, CVariant::from(value), true); }
|
||||
CStatusMessage setAndSave(const T &value, qint64 timestamp = 0) { return m_page.setValue(m_element, CVariant::from(value), timestamp, true); }
|
||||
|
||||
//! Get the key string of this value.
|
||||
const QString &getKey() const { return m_page.getKey(m_element); }
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace BlackMisc
|
||||
const CVariant &getValue(const Element &element) const;
|
||||
|
||||
//! Write the value corresponding to the element's key and begin synchronizing it to any other pages.
|
||||
CStatusMessage setValue(Element &element, const CVariant &value, bool save = false);
|
||||
CStatusMessage setValue(Element &element, const CVariant &value, qint64 timestamp, bool save = false);
|
||||
|
||||
//! Get the key string corresponding to the element.
|
||||
const QString &getKey(const Element &element) const;
|
||||
|
||||
Reference in New Issue
Block a user