Problems with Cache
-
I can't seem to get the cache to work with our web app. Here's the code i have that should set it up:
@
vNetworkManager = new QNetworkAccessManager(0);
connect(vNetworkManager,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyFinished(QNetworkReply*)));
QNetworkDiskCache* diskCache = new QNetworkDiskCache(this);
diskCache->setCacheDirectory(QDesktopServices::storageLocation(QDesktopServices::CacheLocation));
qDebug() << "Cache directory: " << QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
diskCache->setMaximumCacheSize(1000000); //set the cache to 10megs
vNetworkManager->setCache(diskCache);setNetworkAccessManager(vNetworkManager);
@
But when I check in replyFinished, it always says false for page from cache:
@void visiWebPage::replyFinished(QNetworkReply *reply) {
QVariant fromCache = reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute);
qDebug() << "page from cache?" << fromCache.toBool();
}
@Any other magic spell I should be casting to get this to work?
-
Do you see files being created to the "cache directory"?
I have never actually tried to test using "reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute)" but assumed the file was in use because files were being stored on the cache directory.Also, make sure to test accessing a url that is cacheable. (sorry if it is too obvious of comment)