h1. Web Content Management Cache : Configuration and Management

Starting with release 1.2.2 of eXo WCM a cache has been added between the eXo JCR and the WCM. This cache is part of the WCM Composer Service in charge of delivering content to the viewer portlets (Single Content, Content List, ...) and avoiding hereby access to the JCR. This cache is based on eXo Cache, and it is a simple FIFO cache.


h2. Cache level

Each user has an individual cache. Furthermore there is one cache for the anonymous user which is applied for all visitors of the web site (those who did not log in). In public websites most users surf as anonymous users therefore this user is also called _public user_.

Each time a content is published, the cache of all anonymous users (public cache) and the cache of the publisher himself is refreshed. This means that the cache of other users is not immediately invalidated.

It is possible to configure or to deactivate the cache in the publication configuration file. This file is located in:
 $EXO_CONF/wcm/publication-configuration.xml  

For example in the default eXo Tomcat bundle this file is located in [$TOMCAT_HOME/webapps/portal/WEB-INF/conf/wcm/publication-configuration.xml|http://svn.exoplatform.org/projects/ecm/wcm/tags/1.2.2/web/wcmportal/src/main/webapp/WEB-INF/conf/wcm/publication-configuration.xml]


{code}
  <component>
    <key>org.exoplatform.services.wcm.publication.WCMComposer</key>
    <type>org.exoplatform.services.wcm.publication.WCMComposerImpl</type>
    <init-params>
      <value-param>
        <name>useCache</name>
        <value>true</value>
      </value-param>
    </init-params>
  </component>
{code}

You can choose to use the cache or not - the default value of _useCache_ is _true_. Note that with an enabled cache, you may perceive some delay between content publication and website front-end update.

{code}
  <external-component-plugins>
    <target-component>org.exoplatform.services.cache.CacheService</target-component>
    <component-plugin>
      <name>addExoCacheConfig</name>
      <set-method>addExoCacheConfig</set-method>
      <type>org.exoplatform.services.cache.ExoCacheConfigPlugin</type>
      <description>Configures the cache for query service</description>
      <init-params>
	      <object-param>
	        <name>cache.config.wcm.composer</name>
	        <description>The default cache configuration</description>
	        <object type="org.exoplatform.services.cache.ExoCacheConfig">
	          <field name="name"><string>wcm.composer</string></field>
	          <field name="maxSize"><int>300</int></field>
	          <field name="liveTime"><long>600</long></field>
	          <field name="distributed"><boolean>false</boolean></field>
	          <field name="implementation"><string>org.exoplatform.services.cache.concurrent.ConcurrentFIFOExoCache</string></field> 
	        </object>
	      </object-param>
      </init-params>
    </component-plugin>
  </external-component-plugins>

{code} 

You can modify several parameters to control the behavior of your WCM instance.

* maxSize: The maximum number of elements in your cache
* liveTime: The amount of time (in milliseconds) an element is not written or read before it is evicted.
* distributed: Indicates if the cache is distributed
* implementation: FIFO cache is default, in theory you might use a different implementation

h2. Invalidate the cache manually

eXo WCM Cache is based on eXo Cache. The eXo Cache is manageable by JMX. You can use any JMX application and access the MBean called:
{code}exo:service=cache,"name=wcm.composer"{code}

To invalidate the cache you need to call the clearCache() operation. This operation deletes the content of all WCM caches. This means that at the next request of a user the content of a portlet is retrieved from the JCR and the user's individual cache refilled (see above explanations about individual caches).

h2. Cache and Front office

eXo WCM Cache is used in almost all eXo WCM's presentation portlets, this means: Single Content Viewer (SCV), Content List Viewer (CLV), Parameterized Content Viewer (PCV), Parameterized Content List Viewer (PCLV).
In these portlets, after the content is updated, we have to wait some time (the time is configured) until the cache is synchronized with new data. 

Currently, eXo WCM support 2 modes to display contents, to help Administrators and Managers. 
* Live mode: Use cached contents.
* Edit mode: Use real contents.
