[pmwiki-users] Lack of caching of Attach:'d image files

Eemeli Aro eemeli at gmail.com
Tue Apr 14 06:58:31 CDT 2009


2009/4/10 Petko Yotov <5ko at 5ko.fr>:
> On Thursday 09 April 2009 16:56:11 Karl Schilke wrote:
>> ... images that
>> I have Attach:'d to the pages are reloaded every time the page is
>> displayed. This is a) annoying, and b) wasteful of bandwidth.
>
> Do you have in (farm)config.php $EnableDirectDownload = 0; ?
>
> - if yes, remove it AFTER having read these pages:
>   http://www.pmwiki.org/wiki/PmWiki/UploadVariables#EnableDirectDownload
>   http://www.pmwiki.org/wiki/PmWiki/UploadsAdmin

Alternatively, proper caching is still possible even without enabling
direct downloads. The caching of requests that pass through PmWiki is
controlled by the defaults set at the top of pmwiki.php (do not cache
anything, ever) and if $EnableIMSCaching is set, stuff in caches.php
(let stuff sometimes be cached, but only if nothing has changed
anywhere in the wiki since the previous request).

This is mostly(*) fine for actual wiki content, but for attachments
it's not so good: first of all, PmWiki never lets action=download be
cached, but also these files almost certainly will not depend on
anything except themselves and hence forcing them to be reloaded if
something else changes in the wiki is probably useless.

To fix this, you'll need to either overload the download action or
modify upload.php directly, adding the following to the HandleDownload
function right after the 404 conditional (line 173, I believe):

  if (@$EnableIMSCaching) {
    header("Cache-Control: ");
    header("Expires: ");
    $fmod = gmdate( 'D, d M Y H:i:s \G\M\T', filemtime($filepath) );
    if ( @$_SERVER['HTTP_IF_MODIFIED_SINCE'] == $fmod )
      { header("HTTP/1.0 304 Not Modified"); exit(); }
    header("Last-Modified: $fmod");
  }


eemeli

(*) Actually, the headers are wrong when replying with a 304 Not
Modified. It's been a while since I fiddled with this, but I've
replaced lines 40-41 of caches.php with the following. I can't
remember the details of the rationale exactly, but it's probably due
to the exit() happening before $HTTPHeaders is processed.

    if (@$_SERVER['HTTP_IF_MODIFIED_SINCE']==$HTTPLastMod) {
      header("HTTP/1.0 304 Not Modified");
      header("Cache-Control: no-cache");
      header("Expires: ");
      header("Last-Modified: $HTTPLastMod");
      exit();
    }



More information about the pmwiki-users mailing list