Caching in Mura
Mura has a built in caching mechanism that (when enabled) will store content information in memory for reuse throughout a given site. The purpose for this is to improve overall site performance by decreasing the amount of reads to the database.
It's important to note that caching is done in a "lazy load" fashion. This means that the item will not be cached until it is called upon for the first time. It is also important to note that caching uses "soft references". This allows for improved memory management for the JVM. To ensure that there are no issues with soft references, whenever a page is updated the cache gets flushed entirely starting the caching process over again.
Now, there are a few ways to use caching within Mura:
- The first way is to use the built in cf_cacheomatic tag. For those who are not familiar with the tag, it give the user the ability to cache any desired display content.
- The second way is more or less baked into Mura itself but is worth mentioning here. Whenever a page is requested a content bean is created. If caching is turned on then the contents of the content bean are automatically cached for reuse.
Flow Diagram
.jpg)
How to use it
Within Mura's admin console you can go to any given site's "Basic" tab and turn the "Site Caching" option to "on".
Definition
The cf_cacheomatic tag:
<cf_CacheOMatic key="{a unique key}" nocache="{1=don't cache, 0=cache}">
Content here ....
</cf_CacheOMatic>
Example Usage
The cf_cacheomatic tag:
<cf_CacheOMatic key="page#event.getContentBean().getContentID()#" nocache="#request.nocache#"> <p> <cfoutput> The title of this page is #event.getContentBean().getMenuTitle()#. </cfoutput> </p> </cf_CacheOMatic>
Exempting Code from Being Cached
If you have a code snippet that you do not want to ever be cached you can set request.cacheItem=false and any wrapping CacheOMatic tags will not add the rendered output to the cache.
<cf_CacheOMatic key="page#$.content('contentID')#" nocache="#$.event('noCache')#">
<p>
<cfoutput>
The username of the person logged in is #$.currentUser('username')#.
</cfoutput>
<cfset request.cacheItem=false>
</p>
</cf_CacheOMatic>
Programmatically Setting the Cached Items Timespan
If you have a code snippet that you want to be in the sites cache for no longer that a certain timespan you can set request.cacheItemTimeSpan={TimeSpan Object}.
<cf_CacheOMatic key="page#$.content('contentID')#" nocache="#$.event('noCache')#">
<p>
<cfoutput>
The title of this page is #$.content('menuTitle')#.
</cfoutput>
<!--- This item will be in the Mura site cache for no longer than 5
minutes.--->
<cfset request.cacheItemTimeSpan=createTimeSpan(0,0,0,5)>
</p>
</cf_CacheOMatic>