Mobile Number Tracker
Trace Mobile Number Earn Money Online
© TechWelkin.com

Tips: Purging MediaWiki File Cache Pages

Tips for increasing MediaWiki performance.
Samyak Lalit | September 28, 2011 (Last update: April 24, 2021)

Samyak Lalit is an Indian author and disability rights activist. He is the principal author and founder of projects like TechWelkin, WeCapable, Viklangta, Kavita Kosh among many others.

I run many websites that are based on MediaWiki platform. One the of bigger ones is Kavita Kosh –which contains the largest online collection of Indian poetry. The language of this website is Hindi and script is Devanagari. At present I am on a shared server wherein there is a limit of 25% CPU time utilization by each individual account. If any account utilizes more than 25% CPU time for more than 90 seconds –the hosting provider has a policy of blocking the offending account.

With more than 2 million page views every month Kavita Kosh is a very popular website. So, it is not surprising that Kavita Kosh has crossed the CPU time limit during peak time and been blocked by the host twice. Therefore, I needed to take steps to speed up MediaWiki.

Tips for increasing MediaWiki performance.

To reduce the load on CPU –I decided to enable file caching in Kavita Kosh. MediaWiki has a simplistic caching scheme and it caches aggressively. To enable file caching in MediaWiki 1.17 –you should use the following three variables in LocalSettings.php

$wgUseFileCache = true; /* default: false */
$wgFileCacheDirectory = "$IP/cache";
$wgShowIPinHeader = false;

Once the caching is on –MediaWiki begins to keep an HTML copy of every requested page in a file cache (by default it is /wiki/cache directory)… Further request for a page is met by sending the cached HTML page to the client. Remember, MediaWiki caching scheme affects only the anonymous users. Logged in users will get fresh page every time they’ll request one. This clearly means that the page seen by the anonymous users would be out-of-date if there has been changes after it was cached.

I am, at present, facing exactly the same problem. Although, as a temporary measure, I can purge the present cache in order to force MediaWiki to generate fresh pages from the mysql database on future requests. But in a rapidly updated wiki this solution might not hold good for long.

You can purge MediaWiki cache in any of the following ways:

  1. Manually delete the HTML files from cache folder
  2. Set the $wgCacheEpoch variable in LocalSettings.php to the current time
  3. Add &action=purge at the end of any wiki URL and that particular page will be purged
  4. Use Purge extension to provide a purge tab on every page

First three methods work well. But the fourth method is like a catch 22 situation. Extending MediaWiki with Purge extension is a good idea but it will not work unless you invalidate the existing cache. If you’ll not invalidate the existing cache the old files will not show the newly added Purge tab!

Instead of extending MediaWiki you may choose to simply add a purge link directly on page. This can been done by modifying MediaWiki:Sidebar page. Add the following to create a link:

* '''[http:////index.php?title={{#replace:{{PAGENAME}}| |_}}&action=purge Refresh]'''

These are temporary solutions. MediaWiki is not great at managing cache. So, for long term solutions, you should consider either of following options (or may be both):

  1. Opt for a better server wherein you don’t have to put up with the resource limits
  2. Use external caching solutions like Squid or Varnish (for this you’ll have to ask your hosting provider if they provide these tools within your existing package)

I hope this showed you the way on how to clear MediaWiki cache. Do let me know if you have any questions. Thank you for using TechWelkin.

© TechWelkin.com

One response to “Tips: Purging MediaWiki File Cache Pages”

  1. David Lowe says:

    I have a similar problem. When a page is edited the cached version is removed which is desired behaviour But I wish to immediately recache the newly edited page so the updated page is available for anonymous users. How to do this? Cache is not triggered by logged in users, so some method is needed to request the page as though from an anonymous user immediately following the end of the edit process.

Leave a Reply

Your email address will not be published. Required fields are marked *