Cache Macro

The Cache macro caches the content of a page for a predefined period of time.

Usage

{{cache id="<id>" timeToLive="<number of seconds>" maxEntries="<number of entries>"}}
Content to cache
{{/cache}}

Parameters

NameOptionalAllowed valuesDescriptionDefault value
idYesA stringThe identifier used as the key to the cache. In case you might need to generate it using script macros, you can use XWiki syntax. Since the same content can exist on several pages with different results, the uniqueness of the id is not guaranteed.If not defined, the Cache macro uses its own content as id.
timeToLiveYesA numberThe cache duration in seconds which actually represents the number of seconds after which the cache will expire, provided no user accesses the page. The maximum value is 2147483647 seconds.300 (seconds)
maxEntriesYesA numberThe maximum number of cached entries in a given cache.1000

Example

{{cache id="planningPage" timeToLive="2502000"}}
This page won't change for a while, so there is no need to reload it each time.
{{/cache}}

To compute the id based on a script evaluation, you could use the code below:

{{velocity}}
#set ($myid="myComputedId")
{{/velocity}}

{{cache id="~{~{velocity~}~}$myid~{~{/velocity~}~}"}}
This page won't change for a while, so there is no need to reload it each time.
{{/cache}}

OR 

{{cache id="~{~{velocity~}~}$request.id~{~{/velocity~}~}"}}
This page won't change for a while, so there is no need to reload it each time.
{{/cache}}
When using script macros in the content of the Cache macro, then these scripts will be executed only once, before they are cached.

 

Search this space