Caching Code Macro
Explanation
The Caching Code Macro extension replaces the standard Code Macro to make pages holding code display faster. Syntax highlighting is costly to compute, so the extension changes two things:
- Cached: the highlighted code is computed once and kept in a cache, which every later display uses.
- Asynchronous: when the highlighted code isn't in the cache yet, it's computed in the background, so the page is displayed without waiting for it.
Pages keep using the code macro exactly as before. It requires XWiki 15.10 or later and is installed from the Extension Manager.
The asynchronous rendering is enabled by default. To compute the highlighted code while the page is rendered instead, still keeping the cache, see Disable the Asynchronous Rendering of the Caching Code Macro.
First and Later Displays
The first time a code macro is displayed, the page does not wait for it: the highlighted code appears a moment later. Every later display, of this page or of any page holding the same macro, takes the code from the cache.
What Is Cached
Caching Code Macro 1.1+
A cache entry is identified by what the highlighting result depends on: the macro content, its parameters (language, layout, title, image, cssClass, width), whether the macro is inline, the syntax of the macro and of the output, and the current wiki. As a consequence:
- Identical code macros share one cache entry, even on different pages.
- Content generated by a script is cached per distinct content, so each user sees their own.
- Content read through the source parameter is fetched first, with the rights of the current user, and cached per content.
- Editing a macro creates a new entry. Modifying the page resets nothing, except in the case below.
- A macro with a title or an image, when not inline, gets an entry per page, and the relative links and images they hold point to the page holding the macro. When such an entry is computed in the background, it is computed again after that page is modified.
Caching Code Macro <1.1 The result was cached per page and macro position, and reset when the page was modified.
FAQ
Why are the macros of a code macro title missing the first time?
On the first, asynchronous, display the macros inside the title parameter are not executed. They are on the later displays, which use the cached result.
Can I use it with Prism.js Code Macro Replacement?
No. Both extensions replace the code macro, so install only one of them.
More
To find more about the current topic, you can search or use the table below and filter the columns to narrow your choices.