Friday, June 15, 2012

Liferay Ehcache Configuration : Distributed Caching in Liferay

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


Thursday, June 14, 2012

Liferay Search Container : Orderable Columns

In this post we are going to implement the orderable columns for search container.

Following are the steps -

1. Put the following code in your jsp which is used to render the search container.


This If condition is provided to handle the default case. Here defaultColumn and defaultOrder can be replaced with the desired column and order respectively. Here we are sorting the results on the title column.

2.  Here is the TitleComparator.java code -



3.  add the following code to your controller's render method :



4.  Here is the search container part -




Now Title column in the search container will be rendered as clickable and upon clicking will sort the title column data.