summary refs log tree commit diff
path: root/include/Cache.h
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-08-26 13:49:16 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-08-26 13:49:16 +0300
commit7fbfe3af153e37227087771389cf4068ff9a1fa4 (patch)
tree0a7a3e392ce97323409f502edca38202ae18f4c8 /include/Cache.h
parentRemove nick colors (diff)
downloadnheko-7fbfe3af153e37227087771389cf4068ff9a1fa4.tar.xz
Update the cache state at once to avoid being in an invalid state
Diffstat (limited to 'include/Cache.h')
-rw-r--r--include/Cache.h32
1 files changed, 17 insertions, 15 deletions
diff --git a/include/Cache.h b/include/Cache.h

index a64f0514..46107062 100644 --- a/include/Cache.h +++ b/include/Cache.h
@@ -24,36 +24,38 @@ class Cache { public: - Cache(const QString &userId); + Cache(const QString &userId); - void insertRoomState(const QString &roomid, const RoomState &state); - void setNextBatchToken(const QString &token); - bool isInitialized(); + void setState(const QString &nextBatchToken, const QMap<QString, RoomState> &states); + bool isInitialized() const; - QString nextBatchToken(); - QMap<QString, RoomState> states(); + QString nextBatchToken() const; + QMap<QString, RoomState> states(); - inline void unmount(); - inline QString memberDbName(const QString &roomid); + inline void unmount(); + inline QString memberDbName(const QString &roomid); private: - lmdb::env env_; - lmdb::dbi stateDb_; - lmdb::dbi roomDb_; + void setNextBatchToken(lmdb::txn &txn, const QString &token); + void insertRoomState(lmdb::txn &txn, const QString &roomid, const RoomState &state); - bool isMounted_; + lmdb::env env_; + lmdb::dbi stateDb_; + lmdb::dbi roomDb_; - QString userId_; + bool isMounted_; + + QString userId_; }; inline void Cache::unmount() { - isMounted_ = false; + isMounted_ = false; } inline QString Cache::memberDbName(const QString &roomid) { - return QString("m.%1").arg(roomid); + return QString("m.%1").arg(roomid); }