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)



  • Just tested on my application and, at least on windows7, it works.

    @
    reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute);
    @

    returned true form some of the requests.



  • The server might kind-of "forbid" to save the result in a cache. That does make sense on sites with highly dynamic content.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.