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.

 

Related Pages

Search this space

 

Most popular tags

Failed to execute the [groovy] macro
  1. access rights
  2. activity stream
  3. annotation
  4. attachment
  5. comment
  6. Document Tree Macro
  7. export
  8. Extension Manager
  9. Flamingo skin
  10. global user
  11. Groovy event listener
  12. group
  13. nested page
  14. search
  15. skin
  16. syntax
  17. user
  18. user profile
  19. velocity macros
  20. wiki
  21. wysiwyg
  22. XWiki Applications
  23. xwikiattachment_archive table
  24. xwikiattachment table
  25. xwikiattrecyclebin table
  26. xwikiproperties table

[Display all tags from this space]