Moodle
  1. Moodle
  2. MDL-23754 Performance improvements META
  3. MDL-20042

Problem with browser cache and resource download - solve with Etags?

    Details

    • Type: Sub-task Sub-task
    • Status: Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 1.9.5, 1.9.10, 2.0
    • Fix Version/s: None
    • Component/s: Files API, Resource
    • Labels:
      None
    • Affected Branches:
      MOODLE_19_STABLE, MOODLE_20_STABLE
    • Rank:
      6214

      Description

      Hello,

      while working on Federal University of Santa Catarina (http://moodle.ufsc.br), some users have reported the following situation:

      • The teacher uploads file X
      • Then, he links it through a resource on course A
      • The student downloads file X for the first time
      • Some time after, lets say 10 minutes, the teacher uploads another version of the file with the same name
      • When the student tries to download the file again, the browser uses a cached version

      I have tried to user the $CFG->filelifetime = 1, but the problems still persists. I have read about the HTTP cache mechanisms in http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html, and i think the follow happens:

      • If we put the "Expires" too far in the future, the rest of message is discarded, including the new Last-Modified because the old Last-Modified is still valid
      • If we put the "Expires" on the past, the browser will always touch the file in the server, discaregarding the Last-Modified, because the message isn't valid anymore

      So, we cannot solve this problem using this basic header, we have to use ETags: "Entity tags are used for comparing two or more entities from the same requested resource". Basically, the server stores a hash of the file+timemodified (or just the file), and sends to client on the header response, if the hash matches one in the browser caches then it is used, otherwise the browser asks for the server to send the new file.

      It will cause, of course, a performance overhead, but we can think about some way to cache things.

      What do you think?

        Issue Links

          Activity

          Hide
          Gabriel Mazetto added a comment -

          I work with Daniel Neis at Federal University of Santa Catarina and we recently found a way to solve the problem related with browser cache, in a mix of ETags and some other techniques.

          A patch is attached and it's already tested. If therre is any doubt or anything that needs to be clarified about the problem, just drop a comment.

          Show
          Gabriel Mazetto added a comment - I work with Daniel Neis at Federal University of Santa Catarina and we recently found a way to solve the problem related with browser cache, in a mix of ETags and some other techniques. A patch is attached and it's already tested. If therre is any doubt or anything that needs to be clarified about the problem, just drop a comment.
          Hide
          Daniel Neis added a comment -

          It is still true in 2.0

          Show
          Daniel Neis added a comment - It is still true in 2.0
          Hide
          Daniel Neis added a comment -

          The patch submitted by Gabriel Mazetto breaks the database module.
          We will work in an improved version and resubmit the patch.

          Show
          Daniel Neis added a comment - The patch submitted by Gabriel Mazetto breaks the database module. We will work in an improved version and resubmit the patch.
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Adding Petr here... aren't we using etags already (with the content hash or so?). It sounds like an "easy" and "correct" hash to be used to avoid those invalid time-based cachings.

          Show
          Eloy Lafuente (stronk7) added a comment - Adding Petr here... aren't we using etags already (with the content hash or so?). It sounds like an "easy" and "correct" hash to be used to avoid those invalid time-based cachings.
          Hide
          Michael de Raadt added a comment -

          Thanks for reporting this issue.

          We have detected that this issue has been inactive for over a year. It was reported as affecting versions that are no longer supported.

          If you believe that this issue is still relevant to current versions (2.5 and beyond), please comment on the issue. Issues left inactive for a further month will be closed.

          Michael d.

          TW9vZGxlDQo=

          Show
          Michael de Raadt added a comment - Thanks for reporting this issue. We have detected that this issue has been inactive for over a year. It was reported as affecting versions that are no longer supported. If you believe that this issue is still relevant to current versions (2.5 and beyond), please comment on the issue. Issues left inactive for a further month will be closed. Michael d. TW9vZGxlDQo=
          Hide
          Daniel Neis added a comment -

          This issue has been solved by MDL-26028

          Show
          Daniel Neis added a comment - This issue has been solved by MDL-26028
          Hide
          Petr Škoda added a comment -

          Yes, this should be working fine now, closing, thanks.

          Show
          Petr Škoda added a comment - Yes, this should be working fine now, closing, thanks.

            People

            • Votes:
              5 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: