File indexing completed on 2024-11-24 04:53:08
0001 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net> 0002 0003 This file is part of the Trojita Qt IMAP e-mail client, 0004 http://trojita.flaska.net/ 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License as 0008 published by the Free Software Foundation; either version 2 of 0009 the License or (at your option) version 3 or any later version 0010 accepted by the membership of KDE e.V. (or its successor approved 0011 by the membership of KDE e.V.), which shall act as a proxy 0012 defined in Section 14 of version 3 of the license. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #ifndef IMAP_MODEL_COMBINEDCACHE_H 0024 #define IMAP_MODEL_COMBINEDCACHE_H 0025 0026 #include <memory> 0027 #include "Cache.h" 0028 0029 namespace Imap 0030 { 0031 0032 namespace Mailbox 0033 { 0034 0035 class SQLCache; 0036 class DiskPartCache; 0037 0038 0039 /** @short A hybrid cache, using both SQLite and on-disk format 0040 0041 This cache servers as a thin wrapper around the SQLCache. It uses 0042 the SQL facilities for most of the actual caching, but changes to 0043 a file-based cache when items are bigger than a certain threshold. 0044 0045 In future, this should be extended with an in-memory cache (but 0046 only after the MemoryCache rework) which should only speed-up certain 0047 operations. This will likely be implemented when we will switch from 0048 storing the actual data in the various TreeItem* instances. 0049 */ 0050 class CombinedCache : public AbstractCache 0051 { 0052 public: 0053 /** @short Constructor 0054 0055 Create new instance, using the @arg name as the name for the database connection. 0056 Store all data into the @arg cacheDir directory. Actual opening of the DB connection 0057 is deferred till a call to the load() method. 0058 */ 0059 CombinedCache(const QString &name, const QString &cacheDir); 0060 0061 virtual ~CombinedCache(); 0062 0063 QList<MailboxMetadata> childMailboxes(const QString &mailbox) const override; 0064 bool childMailboxesFresh(const QString &mailbox) const override; 0065 void setChildMailboxes(const QString &mailbox, const QList<MailboxMetadata> &data) override; 0066 0067 SyncState mailboxSyncState(const QString &mailbox) const override; 0068 void setMailboxSyncState(const QString &mailbox, const SyncState &state) override; 0069 0070 void setUidMapping(const QString &mailbox, const Imap::Uids &seqToUid) override; 0071 void clearUidMapping(const QString &mailbox) override; 0072 Imap::Uids uidMapping(const QString &mailbox) const override; 0073 0074 void clearAllMessages(const QString &mailbox) override; 0075 void clearMessage(const QString mailbox, const uint uid) override; 0076 0077 MessageDataBundle messageMetadata(const QString &mailbox, const uint uid) const override; 0078 void setMessageMetadata(const QString &mailbox, const uint uid, const MessageDataBundle &metadata) override; 0079 0080 QStringList msgFlags(const QString &mailbox, const uint uid) const override; 0081 void setMsgFlags(const QString &mailbox, const uint uid, const QStringList &flags) override; 0082 0083 QByteArray messagePart(const QString &mailbox, const uint uid, const QByteArray &partId) const override; 0084 void setMsgPart(const QString &mailbox, const uint uid, const QByteArray &partId, const QByteArray &data) override; 0085 void forgetMessagePart(const QString &mailbox, const uint uid, const QByteArray &partId) override; 0086 0087 QVector<Imap::Responses::ThreadingNode> messageThreading(const QString &mailbox) override; 0088 void setMessageThreading(const QString &mailbox, const QVector<Imap::Responses::ThreadingNode> &threading) override; 0089 0090 void setRenewalThreshold(const int days) override; 0091 0092 /** @short Open a connection to the cache */ 0093 bool open(); 0094 0095 private: 0096 /** @short Name of the DB connection */ 0097 QString name; 0098 /** @short Directory to serve as a cache root */ 0099 QString cacheDir; 0100 /** @short The SQL-based cache */ 0101 std::unique_ptr<SQLCache> sqlCache; 0102 /** @short Cache for bigger message parts */ 0103 std::unique_ptr<DiskPartCache> diskPartCache; 0104 }; 0105 0106 } 0107 0108 } 0109 0110 #endif /* IMAP_MODEL_COMBINEDCACHE_H */