Problems with Cache
-
wrote on 22 Dec 2010, 01:12 last edited by
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?
-
wrote on 22 Dec 2010, 02:02 last edited by
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)
-
wrote on 22 Dec 2010, 02:07 last edited by
Just tested on my application and, at least on windows7, it works.
@
reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute);
@returned true form some of the requests.
-
wrote on 22 Dec 2010, 12:57 last edited by
The server might kind-of "forbid" to save the result in a cache. That does make sense on sites with highly dynamic content.
-
wrote on 22 Dec 2010, 21:44 last edited by
Yes, the files show up in the cache folder but at this point I think it is something in the server set up. I'll let you know when I figure out more.
1/5