Uploaded image for project: '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
    • Status: Closed
    • Priority: 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

      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?

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved: