====== Caching ====== [[:DokuWiki]] speeds up browsing through the wiki by caching parsed files((See [[:images]] for info on image caching)). 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, [[man>touch]]((Non-Unix users can simply open the file and save it again -- the idea is to change the file's timestamp)) the local configuration file, ''conf/local.php''. To only force recaching of page xhtml, touch ''inc/parser/xhtml.php''. To purge the editor toolbar (an other cached JavaScript) call http://www.example.com/lib/exe/js.php?purge=true and clean up your browser's cache as well. This especially helps if a new button introduced by a plugin does not show up. ===== 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. * __Instruction Cache__ \\ The instruction cachefile only gets updated when the page, the config files((''conf/dokuwiki.php'' & ''conf/local.php'')), some of DokuWiki's PHP files((''inc/parser/parser.php'' & ''inc/parser/handler.php'')) are changed or plugins are added/removed/enabled/disabled using the [[:plugin:plugin]] manager. * __%%XHTML%% Cache__ \\ The XHTML cache is also affected by a maximum cache age setting ([[:config:cachetime]]), its metadata, some more php files((''inc/parser/xhtml'' & ''inc/parser/metadata'')), 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/*'' ((* being a single character directory name, \\ ''data'' being configurable by [[:config:savedir]])). The files end in ''.xhtml'', ''.i''. Other files are also stored under the cache directory, including: * ''.feed'' --- any rss feeds generated for the wiki * ''.code'' --- portions of the page between ''%% ... %%'' tags after highlighting has been applied. ===== Plugins ===== [[:Plugins]] can now influence cache use via the ''[[devel:event:parser_cache_use|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 [[:plugin:discussion]] & [[:plugin:include]]. To make use of the new functionality a syntax plugin will need to: * save some information relating to the pages it's involved with and the dependency specific to each of those pages. The page's [[:metadata]] is a useful place for this. Metadata can be accessed via ''$INFO['metadata']'' and the ''p_get_metadata()'' and ''p_set_metadata()'' functions. If using metadata please try to stick to [[http://dublincore.org|Dublin Core Metadata standards]]. * add an [[action_plugin]] component to handle the ''[[devel:event:parser_cache_use|PARSER_CACHE_USE]]'' event. Caching itself is handled by the cache object((''inc/cache.php'')). The key parts of that object of interest to plugins are: * the ''depends'' array --- DokuWiki fills this all the known dependencies of the page and then uses standard routines to process them. Plugins can add/modify these dependencies before they are processed. The different types of dependencies are: * ''purge'' --- expire the cache * ''age'' --- expire the cache if its older than age (affected by the metadata value 'date valid') * ''files'' --- expire the cache if it is older than any of the files in this array. Only local files may be added. Take a look at ''[[xref>inc/cache.php]]'' for a list of the files. Perhaps most interestingly the cached xhtml is dependent on the page's metadata. * the cache name, ''cache'' --- a unique identifier under which the cache is stored. Normally it is dependent on the page name, ''%%HTTP_HOST%%'' and the server port. Plugins can generate more complex identifiers, e.g. the [[:plugin:include]] generates identifiers using included page names and whether or not the current user has read access to those pages. === 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);