I have an app that needs to be improved by adding disk cache to it. Because it will be deployed on different devices in the future. I have tested the current version with memory caching on a test device. As expected the first load of a specific page took around 100+ milliseconds. Afterwards it decreased to 50-80 seconds due to memory caching. So my next approach was to improve the performance by adding disk-cache. I have referred to this documentation for how to do this. But after adding disk-cache I don't see any improvement of initial loading time compared to the earlier version of the app.
Can anyone point out what am I doing wrong with my approach? The relevant code snippet is given below.
WebPageCheck.h
bool m_bInitialized; ///< state if the CWMWebPageCheck has been initialized
QUrl m_oUrl; ///< the url which has to be scanned
QStringList m_oRequests; ///< list of requests
QNetworkAccessManager *m_oNetworkManager; ///< networkmanager to start network requests
//added by Isuru for implementing the diskcache
QNetworkDiskCache *m_oDiskCache;
CHashReplyManager m_oReplyManager; ///< reply manager which handles the network replies
WebPageCheck.cpp
CWMWebPageCheck::CWMWebPageCheck(QUrl oUrl)
{
m_bInitialized = false;
m_oUrl = oUrl;
qDebug() << "Starting WebPageCheck with url: " << oUrl;
m_oRequests << "scripts/scripts_WM.js";
m_oRequests << "screens_wm/logbook_wm.html";
m_oNetworkManager = new QNetworkAccessManager();
m_oDiskCache = new QNetworkDiskCache();
m_oDiskCache->setCacheDirectory(QCoreApplication::applicationDirPath() + "/cacheMachine");
m_oNetworkManager->setCache(m_oDiskCache);
connect(m_oNetworkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onReplyFinished(QNetworkReply*)));
connect(&m_oReplyManager, SIGNAL(sigCalculationError(Te_SealRequest)), this, SLOT(onSigCalculationError(Te_SealRequest)));
connect(&m_oReplyManager, SIGNAL(sigCalculationFinished(Te_SealRequest,QByteArray)), this, SLOT(onSigCalculationFinished(Te_SealRequest,QByteArray)));
m_oReplyManager.setCount(m_oRequests.length());
}
It would be really helpful if someone can list the steps that I have to take to enable disk cache using Qt explaining the use of QNetworkRequest
.