我有一个需要通过添加磁盘缓存来改进的应用程序。因为以后会部署在不同的设备上。我已经在测试设备上使用内存缓存测试了当前版本。正如预期的那样,特定页面的第一次加载大约需要 100 多毫秒。之后,由于内存缓存,它减少到 50-80 秒。所以我的下一个方法是通过添加磁盘缓存来提高性能。我已参考此文档了解如何执行此操作。但是在添加磁盘缓存后,与早期版本的应用程序相比,我没有看到初始加载时间有任何改善。
谁能指出我的方法做错了什么?下面给出了相关的代码片段。
网页检查.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());
}
如果有人可以列出使用 Qt 启用磁盘缓存所必须采取的步骤来解释QNetworkRequest
.