Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. Problems with Cache
Forum Updated to NodeBB v4.3 + New Features

Problems with Cache

Scheduled Pinned Locked Moved Qt WebKit
5 Posts 3 Posters 4.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jdarnold
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fcrochik
      wrote on last edited by
      #2

      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)

      Certified Specialist & Qt Ambassador <a href="http://www.crochik.com">Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop... Qt everywhere!</a>

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fcrochik
        wrote on last edited by
        #3

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

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

        returned true form some of the requests.

        Certified Specialist & Qt Ambassador <a href="http://www.crochik.com">Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop... Qt everywhere!</a>

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

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

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jdarnold
            wrote on last edited by
            #5

            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 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved