Liferay is a Gartner Magic Quadrant Leader for the Sixth Year! Find out why
« Back to Configuring

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.

0 Attachments
53963 Views
Average (2 Votes)
The average rating is 4.5 stars out of 5.
Comments
Threaded Replies Author Date
Nice wiki... Using this I have made changes so... Jay Patel February 25, 2011 12:13 AM
Hi I have a very similar issue I need to clear... Jakob Fahrner August 23, 2011 1:03 AM

Nice wiki...

Using this I have made changes so that caching for entity "RatingEntry" is stopped.

But though I would love to know that is it possible to continue using this caching mechanism on these entities rather than stopping caching completely & still remove caching on trigger of particular event?

For example, there is one method named "clearCache()" is there in class "RatingsEntryPersistenceImpl", but there is no way we can invoke this method from service leyer i.e. from class "RatingsEntryLocalServiceUtil".
Posted on 2/25/11 12:13 AM.
Hi

I have a very similar issue
I need to clear Permission cache on trigger (user log out if possible)
But not able to call any methods from PermissionCacheUtil

Completely stopping caching will cause big performance issues
Is there any way to achieve this?
Posted on 8/23/11 1:03 AM in reply to Jay Patel.