Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-48023

Performance issue. "Cache-control: private" on public static files

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      (difficulty: easy, requires administrator access to a Moodle instance)

      1. Install Essential_theme e.g. via git clone https://github.com/gjb2048/moodle-theme_essential theme/essential and configure it with at least a logo in the header (theme_essential | logo);
      2. Double check that Theme designer mode is disabled;
      3. Open your preferred browser;
      4. Set your profile image;
      5. Open the Developer Tools (<F12>) of your browser and focus on the Network tab;
      6. Look at the Response HTTP Headers of the theme URLs: you should not read Cache-Control: private, ...;
      7. Look at the Response HTTP Headers of the profile image URL: you should not read Cache-Control: private, ... when both forcelogin and forceloginforprofileimage in Site administration ► Security ► Site policies are not checked;
      8. Select each default theme and check that each theme file is always served using public as the cache directive;
      9. Test MDL-38743 for any regression.
      Show
      (difficulty: easy, requires administrator access to a Moodle instance) Install Essential_theme e.g. via git clone https://github.com/gjb2048/moodle-theme_essential theme/essential and configure it with at least a logo in the header ( theme_essential | logo ); Double check that Theme designer mode is disabled; Open your preferred browser; Set your profile image; Open the Developer Tools ( <F12> ) of your browser and focus on the Network tab; Look at the Response HTTP Headers of the theme URLs: you should not read Cache-Control: private, ... ; Look at the Response HTTP Headers of the profile image URL: you should not read Cache-Control: private, ... when both forcelogin and forceloginforprofileimage in Site administration ► Security ► Site policies are not checked; Select each default theme and check that each theme file is always served using public as the cache directive; Test MDL-38743 for any regression.
    • Affected Branches:
      MOODLE_27_STABLE
    • Fixed Branches:
      MOODLE_27_STABLE, MOODLE_28_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      m29_MDL-48023_Theme_Setting_Files_Cacheable_By_Both_Browsers_And_Proxies

      Description

      Hi,
      there are some images that my reverse-proxy doesn't cache because of bad Cache-Control header from pluginfile.php.

      The header looks like:
      Cache-Control: private, max-age=31536000, no-transform

      On such files like user icons:
      ...pluginfile.php/5/user/icon/essential/f2?rev=155
      Background image:
      ...pluginfile.php/1/theme_essential/pagebackground/1414917278/lusisbackground.jpg
      Logo:
      ...pluginfile.php/1/theme_essential/logo/1414917278/lusis.jpg
      and so on.

      These files come from theme (plugin). But there is no way for plugin to control Cache-control header.

      In file lib/filelib.php there is:

      if ($lifetime > 0) {
      $private = '';
      if (isloggedin() and !isguestuser()) {
      $private = ' private,';
      }
      header('Cache-Control:'.$private.' max-age='.$lifetime.', no-transform');
      header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT');
      header('Pragma: ');
      }
      

      So every logged in user hits php for numerous static files and creates a big load on server. But with correct headers these files could be served from reverse-proxy without accessing web server at all.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  12/Jan/15