11#include <QDirIterator>
22DiscCache::DiscCache(
const QString &cacheDirectory)
23 : m_CacheDirectory(cacheDirectory)
24 , m_CacheLimit(300 * 1024 * 1024)
25 , m_CurrentCacheSize(0)
27 Q_ASSERT(!m_CacheDirectory.isEmpty() &&
"Passed empty cache directory!");
29 QFile file(indexFileName(m_CacheDirectory));
37 s >> m_CurrentCacheSize;
41 qWarning(
"Unable to open cache directory %s", qPrintable(m_CacheDirectory));
46DiscCache::~DiscCache()
48 QFile file(indexFileName(m_CacheDirectory));
55 s << m_CurrentCacheSize;
62quint64 DiscCache::cacheLimit()
const
67void DiscCache::clear()
72 while (it.hasNext()) {
75 if (it.fileName() == indexFileName(m_CacheDirectory))
85 m_CurrentCacheSize = 0;
88bool DiscCache::exists(
const QString &key)
const
100 QFile file(keyToFileName(key));
102 data = file.readAll();
114 QFile file(keyToFileName(key));
120 m_CurrentCacheSize -= m_Entries.
value(key).second;
129 m_CurrentCacheSize += data.
length();
136void DiscCache::remove(
const QString &key)
148 m_CurrentCacheSize -= m_Entries.
value(key).second;
154void DiscCache::setCacheLimit(quint64 n)
166 return m_CacheDirectory +
QLatin1Char(
'/') + fileName;
169void DiscCache::cleanup()
172 auto fivePercent = quint64(m_CacheLimit * 0.05);
174 while (m_CurrentCacheSize > (m_CacheLimit - fivePercent)) {
179 while (it.hasNext()) {
182 if (it.value().first < oldestDate) {
183 oldestDate = it.value().first;
184 oldestKey = it.key();
Binds a QML item to a specific geodetic location in screen coordinates.
qsizetype length() const const
QDateTime currentDateTime()
bool contains(const Key &key) const const
iterator insert(const Key &key, const T &value)
size_type remove(const Key &key)
T value(const Key &key, const T &defaultValue) const const
bool isEmpty() const const