service/NativeDocumentCache.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "NativeMailDocument.h" | ||
| 4 | #include <QCache> | ||
| 5 | #include <optional> | ||
| 6 | |||
| 7 | // Owned exclusively by the native preparation worker. Images and external | ||
| 8 | // permissions are deliberately absent: each consumer must resolve them anew. | ||
| 9 | class NativeDocumentCache { | ||
| 10 | public: | ||
| 11 | static constexpr int RamBytes = 6 * 1024 * 1024; | ||
| 12 | static constexpr int DiskSlots = 64; | ||
| 13 | static constexpr qint64 MaxEntryBytes = 2 * 1024 * 1024; | ||
| 14 | explicit NativeDocumentCache(QString directory); | ||
| 15 | static QByteArray key(const QString &database, qint64 folder, qint64 uid, | ||
| 16 | quint32 uidValidity, const QByteArray &html); | ||
| 17 | static QByteArray keyWithDigest(const QString &database, qint64 folder, qint64 uid, | ||
| 18 | quint32 uidValidity, const QByteArray &htmlDigest); | ||
| 19 | std::optional<NativeMailDocument> get(const QByteArray &key); | ||
| 20 | void put(const QByteArray &key, const NativeMailDocument &document); | ||
| 21 | 320 | int ramBytes() const { return m_memory.totalCost(); } | |
| 22 | private: | ||
| 23 | QString path(const QByteArray &key) const; | ||
| 24 | QString m_directory; | ||
| 25 | QCache<QByteArray, NativeMailDocument> m_memory{RamBytes}; | ||
| 26 | }; | ||
| 27 |