Table of Contents

Caching

DokuWiki speeds up browsing through the wiki by caching parsed files1). If a currently cached version of a document exists, this cached copy is delivered instead of parsing the data again. On editing and previewing no cache is used.

Purging the cache

To force the recaching of a single page just add the parameter purge to the URL. Example:

http://www.example.com/namespace/page?purge=true

To force recaching of all pages, including page instructions, touch2) the local configuration file, conf/local.php.

To only force recaching of page xhtml, touch inc/parser/xhtml.php.

Two-Stage-Caching

DokuWiki uses two cache files per page. To understand this you need to know that a page is parsed to an intermediate instruction format first before it is rendered to XHTML. DokuWiki caches both – the instructions and the rendered XHTML.

* XHTML Cache
The XHTML cache is also affected by a maximum cache age setting (cachetime), its metadata, some more php files5), whenever the existence state of an internal link changes (i.e. the link target page is created or deleted) or when an RSS feed needs refreshing.

Location

The XHTML and instruction cache are located in data/cache/* 6). The files end in .xhtml, .i. Other files are also stored under the cache directory, including:

Plugins

Plugins can now influence cache use via the PARSER_CACHE_USE event. This allows plugins which introduce additional dependencies for specific pages to check those dependencies and force DokuWiki to refresh the page when it wouldn't normally.

developer note

Up until now plugin developers have only been able to turn off caching completely. This has been necessary for plugins like discussion & include. To make use of the new functionality a syntax plugin will need to:

Caching itself is handled by the cache object7). The key parts of that object of interest to plugins are:

Individual Page Cache Expiry

As described above, DokuWiki verifies the validity of the cache rather than actively expiring the cache. However, the page xhtml is dependent on its metadata. That is, if the metadata file is more recent than the cache, DokuWiki will determine that the cache is invalid and re-render the page. So, we can update the metadata to expire the cache.

/* code to expire the cached xhtml of page ns:page
 * $id = 'ns:page';
 * $data = array('cache' => 'expire');  // the metadata being added
 * $render = false;                     // no need to re-render metadata now
 * $persistent = false;                 // this change doesn't need to persist passed the next metadata render.
 */
p_set_metadata($id, $data, $render, $persistent);
1) See images for info on image caching
2) Non-Unix users can simply open the file and save it again – the idea is to change the file's timestamp
3) conf/dokuwiki.php & conf/local.php
4) inc/parser/parser.php & inc/parser/handler.php
5) inc/parser/xhtml & inc/parser/metadata
6) * being a single character directory name,
data being configurable by savedir
7) inc/cache.php