Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-40836

QNetworkDiskCache: expiration calculation with Last-Modified time not working well



    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Done
    • Affects Version/s: 5.3.1
    • Fix Version/s: None
    • Component/s: Network: Cache
    • Labels:


      This is expiration calculation in RFC 13.2.4.
      "If none of Expires, Cache-Control: max-age, or Cache-Control: s- maxage (see section 14.9.3) appears in the response, and the response does not include other restrictions on caching, the cache MAY compute a freshness lifetime using a heuristic. The cache MUST attach Warning 113 to any response whose age is more than 24 hours if such warning has not already been added.
      Also, if the response does have a Last-Modified time, the heuristic expiration value SHOULD be no more than some fraction of the interval since that time. A typical setting of this fraction might be 10%."

      Heuristic with Last-Modified time in Qt does not work well.
      This is heuristic code in QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed function.

      // RFC 2616 13.2.4 Expiration Calculations
      if (!expirationDate.isValid()) {
          if (lastModified.isValid()) {
              int diff = currentDateTime.secsTo(lastModified);
              expirationDate = lastModified.addSecs(diff / 10);
              if (httpRequest.headerField("Warning").isEmpty()) {
                   QDateTime dt;
                   if (dt.daysTo(currentDateTime) > 1)
                       httpRequest.setHeaderField("Warning", "113");
      // the cache-saving code below sets the expirationDate with date+max_age
      // if "max-age" is present, or to Expires otherwise
      int freshness_lifetime = dateHeader.secsTo(expirationDate);
      response_is_fresh = (freshness_lifetime > current_age);

      Diff is negative value, because last-modified is earlier than current time.
      (*. http://qt-project.org/doc/qt-5/qdatetime.html#secsTo)
      Because diff is negative value, Expiration date will be earlier than last-modified.
      ExpirationDate is earlier than dateHeader, and freshness_lifetime is also negative value.
      So response_is_fresh value is false. It means that disk cache heuristic does not cache files.


        No reviews matched the request. Check your Options in the drop-down menu of this sections header.



            • Assignee:
              peter-har Peter Hartmann
              dongheon.jung JUNG DONG-HEON
            • Votes:
              0 Vote for this issue
              4 Start watching this issue


              • Created:

                Gerrit Reviews

                There are no open Gerrit changes