Writing cache files async

This commit is contained in:
fourtf 2019-08-20 22:06:27 +02:00
parent d6627b531e
commit 7d842e6cf7
2 changed files with 12 additions and 12 deletions

View file

@ -47,18 +47,20 @@ QString NetworkData::getHash()
return this->hash_; return this->hash_;
} }
void NetworkData::writeToCache(const QByteArray &bytes) void writeToCache(const std::shared_ptr<NetworkData> &data,
const QByteArray &bytes)
{ {
if (this->useQuickLoadCache_) if (data->useQuickLoadCache_)
{ {
QFile cachedFile(getPaths()->cacheDirectory() + "/" + this->getHash()); QtConcurrent::run([data, bytes] {
QFile cachedFile(getPaths()->cacheDirectory() + "/" +
data->getHash());
if (cachedFile.open(QIODevice::WriteOnly)) if (cachedFile.open(QIODevice::WriteOnly))
{ {
cachedFile.write(bytes); cachedFile.write(bytes);
}
cachedFile.close(); });
}
} }
} }
@ -134,7 +136,7 @@ void loadUncached(const std::shared_ptr<NetworkData> &data)
} }
QByteArray bytes = reply->readAll(); QByteArray bytes = reply->readAll();
data->writeToCache(bytes); writeToCache(data, bytes);
NetworkResult result(bytes); NetworkResult result(bytes);

View file

@ -53,8 +53,6 @@ struct NetworkData {
QString getHash(); QString getHash();
void writeToCache(const QByteArray &bytes);
private: private:
QString hash_; QString hash_;
}; };