Cache the Output of Slow Pages
Last modified by Eleni Cojocariu on 2026/10/21 14:27
Content
Steps
Keep the rendered result of the pages that are expensive to produce, so that only the first reader after each expiry pays for them. Which pages those are is a measurement, not a guess: see Performance.
- Find the page whose rendering holds the time, with Find What Makes a Request Slow.
- Enable the cache in xwiki/WEB-INF/xwiki.properties.
core.renderingcache.enabled = true - List the pages to cache. Each value is a Java regular expression matched against the full document reference, and the property can be repeated.
core.renderingcache.documents = mywiki:Reports\.Monthly core.renderingcache.documents = mywiki:Reports\..* - Choose how long a cached result stays valid, in seconds, and how many results are kept. core.renderingcache.size counts results, not documents: one page produces a separate entry per action, language and query string.
core.renderingcache.duration = 300 core.renderingcache.size = 100 - Restart XWiki, since these properties are read at startup.
- Request the page twice and compare the two. The first request renders it and fills the cache, the second is served from the cache, and the elapsed time tree of the second no longer contains the steps that produced the content.
curl -s -o /dev/null -w "%{time_total}s\n" https://wiki.example.com/xwiki/bin/view/Reports/Monthly curl -s -o /dev/null -w "%{time_total}s\n" https://wiki.example.com/xwiki/bin/view/Reports/Monthly
FAQ
How do I see the fresh version without waiting for the expiry?
Add refresh=1 to the page's URL. Saving the page also refreshes its own cache entry.
Can the cache be flushed from code?
Yes, through the com.xpn.xwiki.internal.cache.rendering.RenderingCache component.
@Inject
private RenderingCache renderingCache;
renderingCache.flushWholeCache();
renderingCache.flushCache(new DocumentReference("mywiki", "Reports", "Monthly"));Should I cache a page that shows different content per user?
No. An entry is keyed by the action, the language and the query string, not by the reader, so every reader of a given URL is served the same cached result.