Although the OpenCms template mechanism is fast, it is often handy to cache certain dynamically created pages or page elements to decrease the number of database queries at runtime. The use of a caching mechanism can increase the performance of your Website. For example, to build a page navigation it requires a lot of database queries. If a navigation can be cached, it is build only once and then called from the cache.

Please look at the FlexCache examples to understand the caching mechanism.

The FlexCache

The FlexCache is a new cache implementation for OpenCms pages. It is currently used only to cache JSP and elements included by JSP, but it is likely that it will be extended to other resource types in the future. The FlexCache is an evolution of the "Element Cache" of earlier OpenCms versions, based on the same principles but much easier to use.

The FlexCache is able to cache a page and all sub-elements of a page. All elements are cached as separate entries. Headers and redirects are also cached. This means if you have a page (a) that includes a sub-element (b), both (a) and (b) will be cached, not just one combined entry for (a+b). Every element has it's own cache directives which are attached to the file property cache, using the OpenCms Workplace file context menue. The cache directives decide under which circumstances an element is cachable or not. So for example if (a) is cachable and sub-element (b) is not, the cache stores an entry for (a) and dynamically inserts (b) when (a) is requested. Moreover, the cache directives allows "variation entrys" which means there can be more than one version of an element in the cache. This is highly useful in a number of cases.

Here's a simple example on how to use the FlexCache directives: Let's say you have a website accessible for all users with optional login. In case a user is not logged in, a small area in your template should display a simple "Please log in here" HTML form. If the user has successfully logged in, this small area should be replaced by a "You are logged in as user xxxx" message. With the FlexCache, you just place the whole login-area in a sub-element that gets included by the main template. You could then set the cache directives of the main page to always (indicating that this page is always cachable) and the cache directives of the sub-element to groups=(Guests), indicating that unauthorized requests can be cached. So if the page gets requested by a user who is not logged in, both elements will be drawn from the cache, resulting in a very fast page delivery time. If the user is logged in, the main part of the page (the top element) is still drawn from the cache, and only the small login box is dynamically build at runtime with the users name, resulting also in a much faster performance than calculating the whole page dynamically.

The FlexCache is very powerful and there are many more hands-on, real world scenarios how it can be used. Please have a look at the Flex Examples which are available as a separate module for a demonstration. The rest of this page describes the various configuration options for the FlexCache.

Some simple examples to show how to use the FlexCache

Example FlexCache configuration settings for the file

Usage of the FlexCache Administration page in the OpenCms backoffice.

Introduction on how to attach FlexCache directives to resources.

Reference and explanations of all possible FlexCache directives.

Examples to illustrate the usage of FlexCache directives on resources.

Description how to control the internal buffering of template based pages.

Reference of all FlexCache request parameters to control the flex cache.

A page to test the new and improved LRU policy of the FlexCache