How to prevent MediaWiki caching pages

From Cookipedia

Revision as of 04:10, 17 March 2012 by Chef (talk | contribs) (Use Extension:MagicNoCache)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Adding this as a personal aide-memoir, that may also prove useful to others.

MediaWiki caching

A MediaWiki caches pages for efficiency reasons. The MediaWiki pages are created by parsing multiple tables within a large database. Whilst this provides flexibility it is not terribly efficient. To greatly improve this situation, the MediaWiki engine saves the latest 'built' page in a cache and delivers that when a page is requested.

The cache automatically updated at various times and when a page is edited.

Why is this a problem

On this Wiki there are a number of functions that have been added that give enhanced features, many of these are not integral to the MediaWiki, for example: The Meat cooking time calculator. When making backend content changes to these pages, the cache needs to be disabled or the page needs to be edited and re-saved so that the backend changes can be seen. This is a pain!

Possible solutions

  • Edit and save the page
  • Edit LocalSetting.php and temporarily disable the cache by switching the commented sections or amending the logic:

$wgEnableParserCache = true;
$wgCachePages = true;

#$wgEnableParserCache = false;
#$wgCachePages = false;

Use Extension:MagicNoCache

  • disabled 17/3/2012 - fails with my keywords module
  • Install Extension:MagicNoCache & include the NOCACHE magic word. !Requires two underscores either side! Cannot show an example on this page as it is parsed regardless of nowiki (and other similar tags).

See also

Clear cache on edit/save of LocalSettings.php

# When you make changes to this configuration file, this will make
# sure that cached pages are cleared.
$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );

Clear cache of a specific page (Perl)

sub update_cache {
    my $ua = LWP::UserAgent->new;
    $ua->agent("MyApp/0.1 ");

    my $url =
"http://www.cookipedia.co.uk/wiki/index.php/Welcome_to_Cookipedia?action=purge";
    my $req = HTTP::Request->new( POST => $url );
    $req->content_type('application/x-www-form-urlencoded');
    $req->content('query=libwww-perl&mode=dist');

    # Pass request to the user agent and get a response back
    my $res = $ua->request($req);

    if ( $res->is_success ) {
        print "updated and cache cleared ";
    }
    else {
        print $res->status_line, "\n";
    }
}