How to prevent MediaWiki caching pages: Difference between revisions

No edit summary
No edit summary
 
Line 2: Line 2:
|title=How to prevent MediaWiki caching pages
|title=How to prevent MediaWiki caching pages
|titlemode=replace
|titlemode=replace
|keywords=How to prevent MediaWiki caching pages
|keywords=#howtopreventmediawikicachingpages #help #meatcookingtimecalculator
|hashtagrev=12032020
|description=Adding this as a personal aide-memoir, that may also prove useful to others. A MediaWiki caches pages for efficiency reasons.
|description=Adding this as a personal aide-memoir, that may also prove useful to others. A MediaWiki caches pages for efficiency reasons.
|og:image=https://www.cookipedia.co.uk/img/cookipedia-logo.png
|og:type=article
}}
}}
<!-- /seo -->
<!-- /seo -->
Adding this as a personal aide-memoir, that may also prove useful to others.
Adding this as a personal aide-memoir, that may also prove useful to others.
<GoogleBanner></GoogleBanner>
 
====MediaWiki caching====
====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.
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.
Line 32: Line 32:
</pre>
</pre>
==== Truncate database table l10n_cache ====
==== Truncate database table l10n_cache ====
From the [http://www.mediawiki.org/wiki/Manual:L10n_cache_table Mediawiki page covering this table].
From the [http://www.mediawiki.org/wiki/Manual:L10n_cache_table Mediawiki page covering this table]: ''"Its content can be deleted and excluded from backups as it will be regenerated when needed."''
Its content can be deleted and excluded from backups as it will be regenerated when needed.<ref>The l10n_cache table. Its content can be deleted and excluded from backups as it will be regenerated when needed.</ref>
 
This table can become massive. I've seen it as large as 5.4 gb on this server.
==See also==
==See also==
====Clear cache on edit/save of LocalSettings.php====
====Clear cache on edit/save of LocalSettings.php====
Line 41: Line 42:
$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
</pre>
</pre>
====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)====
====Clear cache of a specific page (Perl)====
<pre>
<pre>
Line 64: Line 67:
}
}
</pre>
</pre>
 
* http://www.mediawiki.org/wiki/Manual:PurgeList.php
* http://meta.wikimedia.org/wiki/MediaWiki_FAQ#How_do_I_purge_cached_pages.3F
* http://meta.wikimedia.org/wiki/MediaWiki_FAQ#How_do_I_purge_cached_pages.3F
* http://www.mediawiki.org/wiki/Extension:MagicNoCache
* http://www.mediawiki.org/wiki/Extension:MagicNoCache
[[Category:Useful information]]
[[Category:Useful information]]
[[Category:Help]]
[[Category:Help]]
{{BottomBanner}}
<!-- footer hashtags --><code 'hashtagrev:12032020'>#howtopreventmediawikicachingpages #help #meatcookingtimecalculator </code><!-- /footer_hashtags -->

Latest revision as of 04:40, 12 December 2014


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