Interwiki cache

Jump to: navigation, search

MediaWiki has a database table (interwiki table) for interwiki prefixes. This is by default used directly, but two types of caching can be used for better performance.

"Interwiki cache" can thus refer to two types of caching, but in Wikimedia context it usually refers to CDB caching.

Database and memcached[edit]

When memcached is enabled, the interwiki prefixes of the database table will be cached too. This can be controlled using the $wgInterwikiExpiry setting.

This cache can be cleared using the clearInterwikiCache.php script. It removes the caching based on the prefixes found in the database table.

CDB interwiki cache[edit]

When $wgInterwikiCache is set to point to a CDB file, that file is then used as a replacement for the database.

MediaWiki does not contain a script to build or update such a CDB cache file (bug 33395), however WikimediaMaintenance contains dumpInterwiki.php and rebuildInterwiki.php which are custom Wikimedia-specific scripts used for the CDB cache of all Wikimedia wikis.

The $wgInterwikiScopes and $wgInterwikiFallbackSite settings are used for this caching.

Setting this up on your own wiki[edit]

See Interwiki cache/Setup for your own wiki for cheap(er) ways to do it, assuming you want interwiki links on your wiki to take readers to the Wikimedia projects, and also for a bunch on info about the interwiki cdb file innards. For the more painful but more correct approach, see below.

  • You will need a copy of extension/WikimediaMaintenance [1]; place this in the extensions directory in the root of your MediaWiki installation.
  • Retrieve the files all.dblist [2], special.dblist [3], and langlist [4] and put them somplace (e.g. in a subdir in the base of your MediaWiki installation) for convenience.
  • Edit extension/WikimediaMaintenance/dumpInterwikis.php and change the paths /home/wikipedia/common for those three files to the path to the directory where you just put them.
  • Since you most likely don't use our CommonSettings.php etc setup, edit extension/WikimediaMaintenance/WikimediaMaintenance.php and change the line
    return MWInit::interpretedPath( '../wmf-config/CommonSettings.php' );
  • return MWInit::interpretedPath( 'LocalSettings.php' );
  • From the base of your MediaWiki installation, do
    echo 'print wfWikiID();' | php maintenance/eval.php
Add this value to all.dblist, assuming it's not already in there. If it does not start with a known language code (e.g. it is, say, 'wikitech-mw_ instead of something nice like frwiktionary), add it also to special.dblist. You can check the language codes in the langlist file you copied over.
  • From the base of your MediaWiki installation, do
    php extensions/WikimediaMaintenance/dumpInterwiki.php -o cache/new-interwikis.db
  • From the base of your MediaWiki installation, make a copy of any existing cache/interwiki.db file you may have and then do
    cp cache/new-interwikis.db cache/interwiki.db
  • Edit LocalSettings.php and add
    $wgInterwikiCache = "$IP/cache/interwiki.cdb";

Now shortcuts and all other iw links should work for your project. Note that if you added it to 'special.dblist', it will behave as though it is a 'wikipedia' with en as the default language.

Retrieving interwikis[edit]

To view the interwiki prefixes, you can use the API (action=query&meta=siteinfo&siprop=interwikimap) or install the Interwiki extension. These return the prefixes in the database table, and since MW 1.19 these will also work correctly for CDB cached interwiki prefixes. When using memcached, they will return prefixes directly from the database. This could cause a slight difference because the database may have been modified since the last cache version, but since r114912 deleted entries are removed from the memcached cache too.