Caching Page Objects

Improve the website performance by caching parts of a web page rendering

When you have identified slow functions, you can have the website cache their output and use this cache instead of actual function calls, thus reducing the response time and boosting the overall performance.

For this, C1 CMS provides a specific function called "PageObjectCache" that can be wrapped around other functions and cache their output. The first time the wrapped function will be executed and the result will be cached for the specific number of seconds (60 by default). The second time and so on, the cache will be used instead.

Let's take a closer look at this function.

Composite.Utils.Caching.PageObjectCache

The function allows you to cache parts of a web page rendering in order to reuse the rendering result across multiple requests. The function can wrap a single function call or a section of XHTML that contains multiple function calls.

When caching, the embedded function calls will not be executed.

You can use this function to improve performance on sites where full page caching is not an option or common functionality (like top bars, news teasers etc.) are shared across many pages.

Example:

<f:function name="Composite.Utils.Caching.PageObjectCache" xmlns:f="http://www.composite.net/ns/function/1.0">
  <f:param name="ObjectToCache">
    <h1>
      This is cached! <f:function name="Composite.Utils.Date.Now" />
    </h1>
  </f:param>
  <f:param name="ObjectCacheId" value="Cached timer 01 unique id" />
  <f:param name="SitemapScope" value="Level1" />
  <f:param name="SecondsToCache" value="3" />
  <f:param name="LanguageSpecific" value="True" />
</f:function>

Parameters

It has two required parameters: an object to cache (functions, markup) and the cache ID. The other three parameters are optional and allows you to fine-tune the caching.

ObjectToCache

(Object) Required. What you want to cache - this can be a single function call or a section of markup containing one or more function calls.

ObjectCacheId

(String) Required. An ID unique to the content being cached. This value is used - in conjunction with the Page scope - to define a unique cache key.

SitemapScope

(SitemapScope) Optional. The page scope the cached data should be shared on. By default the page scope is 'this website', but you can change it to page specific caching and more.

SecondsToCache

(Int32) Optional. The number of seconds the cached object should be reused. Default is 1 minute (60 seconds).

LanguageSpecific

(Boolean) Optional. If 'true', the cached object should be uniquely cached per website language; otherwise, it should be commonly shared among languages. Default is 'true'.

Notes

  1. The cache key can be a dynamic value, taken, for example, from a function that returns a random number from 1 to 5. This will give 5 caches -and the output might look and feel random but actually be cached.
  2. It doesn't works on personalized content (unless you have something personalized in the cache key).