This wiki does not contain official documentation and is currently deprecated and read only. Please try reading the documentation on the Liferay Developer Network, the new site dedicated to Liferay documentation.      DISCOVER Build your web site, collaborate with your colleagues, manage your content, and more.   DEVELOP Build applications that run inside Liferay, extend the features provided out of the box with Liferay's APIs.   DISTRIBUTE Let the world know about your app by publishing it in Liferay's marketplace.   PARTICIPATE Become a part of Liferay's community, meet other Liferay users, and get involved in the open source project.  ehCache Configuration
Introduction #
This article collates information from various Liferay engineers about configuring Liferay's built-in caching, ehCache.
Enable/disable caching for the different classes in the portal#
The default hibernate cache configs are:
- portal-impl/src/ehcache/hibernate-clustered.xml
 - portal-impl/src/ehcache/hibernate-terracotta.xml
 - portal-impl/src/ehcache/hibernate.xml
 
In there make sure that you are configuring the actual mapping class rather than the interface.
    <cache
        name="com.liferay.portal.model.impl.UserImpl"
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="600"
        overflowToDisk="false"
    />
    <cache
        name="com.liferay.portal.model.impl.PermissionImpl"
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="600"
        overflowToDisk="false"
    />Any class which is not configured with a specific configuration will be provided with defaults which are derived from the <defaultCache/> element (note that each of the above files provides a different defaultCache appropriate to that usage):
<defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="600" overflowToDisk="false" />
This behavior may or may not suite your usage. Tuning is usually required for optimal performance. It's prudent to take a few minutes to evaluate system use, and customize those cache configurations.
Issues with ehCache configuration and solutions#
1) hibernate.xml (and variants) are referenced by the property net.sf.ehcache.configurationResourceName, who is not used by any class or file in the portal. I have not found any direct reference to those files (as it should be). These facts seems to indicate that hibernate.xml is not use at any point at any point in the portal, and even if you change configurations they are not reflected at runtime.
- net.sf.ehcache.configurationResourceName is only valid if using EhCache provided Hibernate Cache Provider. Cache Providers provided by Hibernate use property hibernate.cache.provider_configuration_file_resource_path to defined where to load the cache configuration. I will be soon upgrading trunk to use EhCache 1.7 so that we can provide a bundled configuration for Terracotta Distributed EhCache. Will be also adding those jars. The Terracotta Distributed EhCache uses the regular hibernate.cache.provider_configuration_file_resource_path property but the configuration format is different from regular ehcache.xml.
 
The Terracotta + Liferay bundle is available on EE only.
2) If you change configurations in liferay-multi-vm(-clustered).xml those changes take effect, but if you try to change the cache configuration for the cache of a class that it is managed by hibernate (that is Impl classes) then you have to reference those objects as 'com.liferay.portal.kernel.dao.orm.EntityCache.com.liferay.whatever.BlaImpl'. This seems to affect how the cache is managed but you can not disable caching for a given object.
- Entity Cache can be disabled per entity from portal-ext.properties like this:
 
- value.object.entity.cache.enabled.com.liferay.portal.model.User=false
 
Adding this line to your portal-ext.properties will impact these variables in the model implementation:
public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get( "value.object.entity.cache.enabled.com.liferay.portal.model.User"), true); public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.portal.util.PropsUtil.get( "value.object.finder.cache.enabled.com.liferay.portal.model.User"), true);
These variables are used in the persistence to decide whether caching is enabled or not.