[Home]WikiPatches/WikiToHTMLCache

UseModWiki | WikiPatches | RecentChanges | Preferences

I noticed that when you use the cache, everything is stored in the cache. That means, if you apply the /GetAdminBar Patch and display a page so that it gets cached, everybody will see the Adminbar (OK, without the Adminpassword you can't really use it, but it's still displayed). Also all the Header and Footer-Stuff that should be allowed to be managed individually by setting Preferences will be stored and therefore the individual settings from the first person to browse the page will be there "forever" (or at least until somebody else updates the cache).

Because I didn't want that behaviour, I wrote a little Patch that will cache just the content of the page (what is returned from WikiToHTML) and create headers and footers each time individually.

CAUTION: If you already used a cache and want to apply this patch, you have to either delete all cache-files or manually recreate all files! Else, there will be lots of confusion, doubled display of HTML-Header, footer and even the http-header!

Patch

In subroutine
 sub DoCacheBrowse
change
  if (-f $idFile) {

    local $/ = undef;   # Read complete files
    concat(INFILE, "<$idFile") or return 0;
    $text = <INFILE>;
    close INFILE;
    print $text;
    return 1;
  }
to

  if (-f $idFile) {
    local $/ = undef;   # Read complete files
    concat(INFILE, "<$idFile") or return 0;
    $text = &GetHeader($query, &QuoteHtml?($query),'');
    $text .= <INFILE>;
    $text .= &GetFooterText($query,'');
    close INFILE;
    print $text;
    return 1;
  }

In

 sub BrowsePage
change the last line from
  &UpdateHtmlCache?($id, $fullHtml)  if $UseCache;
to
  &UpdateHtmlCache?($id, &WikiToHTML($Text{'text'}))  if $UseCache;

And last, in

 sub DoWikiRequest
rearrange one line from
  &InitLinkPatterns();
  if (!&DoCacheBrowse()) {
    eval $BrowseCode;
    &InitRequest() or return;
to
  &InitLinkPatterns();
  &InitRequest() or return;
  if (!&DoCacheBrowse()) {

    eval $BrowseCode;
(This is done, because GetHeader and GetFooterText rely on variables initialized here)

Note: With this patch applied, the cache gets less efficient, because it just saves the time of executing WikiToHTML! It will most likely only save time on rather big pages! On the other hand it shouldn't be slower than without using a cache at all.

Hmm, I'll look into this. So far I almost never used the caching stuff. Thanks for pointing out this problem. -- MarkusLude


UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited December 9, 2007 3:09 am by MarkusLude (diff)
Search: