How to prevent MediaWiki caching pages

From Cookipedia
Jump to: navigation, search


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;

Truncate database table l10n_cache

From the Mediawiki page covering this table: "Its content can be deleted and excluded from backups as it will be regenerated when needed."

This table can become massive. I've seen it as large as 5.4 gb on this server.

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 all pages (PurgeList.php)

php /var/www/vhosts/domain.com/httpdocs/wiki/maintenance/purgeList.php --purge --all

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";
    }
}


#howtopreventmediawikicachingpages #help #meatcookingtimecalculator