Tips: Purging MediaWiki File Cache Pages

Keeping a File Cache can improve performance of a MediaWiki installation. But when you make changes in MW skin, you may need to empty file cache. Learn how.

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

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:

Manually delete the HTML files from cache folder

Set the $wgCacheEpoch variable in LocalSettings.php to the current time

Add &action=purge at the end of any wiki URL and that particular page will be purged

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:

Lalit Kumar is the Principal Author and Founder of TechWelkin. He is a web explorer and he enjoys finding useful information on the Internet. He loves to put things together to create a bigger solution. Lalit is passionate about technology, languages and literature. You can contact Lalit via email (techwelkin [at] gmail [dot] com) or Facebook (facebook.com/techwelkin).