Liferay Portal uses Ehcache to support distributed caching.
1. Enable distributed caching
To enable the distributed caching in liferay portal just set the following property in the portal-ext.properties file.
cluster.link.enabled=true
2. Default Hibernate cache settings
In Liferay Portal, hibernate is configured to use the Ehcache and default caching configurations are specified in the hibernate-clustered.xml file.
Following configuration is used by default for all the Liferay entities.
3. Customizing Hibernate Cache Settings
Let say we want to customize the hibernate cache settings for MBMessage Entity. Following are the steps to achieve our goal -
create a new folder say myEhcache in the [Tomcat Home]/webapps/ROOT /WEB-INF/classes/ folder and copy the default hibernate-clustered.xml file in the myEhcache folder.
Edit the hibernate-clustered.xml file and an entry for MBMessage Entity
4. Add an entry to portal-ext.properties file to provide the path of your custom hibernate-clustered.xml file
net.sf.ehcache.configurationResourceName=/myEhcache/hibernate-clustered.xml
Restart the server.
5. Viewing Cache Configuration in jconsole -
jconsole can be used to view the current cache settings applied. Following is screenshot displaying the cache configuration for MBMessageImpl class:
As we customized the Hibernate cache settings, Cache settings for the clustered environment can also be configured via following files -
1. liferay-single-vm.xml
2. liferay-multi-vm-clustered.xml