Caching (EhCache)
Introduction#
Starting with Liferay 4.3.1 Caching (OSCache) has been replaced by Ehcache. There were a few motivations, initially inspired by a blog entry from community member Mika Koivisto:
"After using the new ehcache and its replication feature I’m convinced thats the caching solution that should be used over OSCache especially after seeing a benchmark where it kicked the crap out of OSCache."
- Ehcache provides better performance. See http://gregluck.com/blog/archives/2006/03/comparative_cac.html
- Ehcache has advanced replication features See [http://ehcache.sourceforge.net
- |Ehcache clustering options is more robust. See http://ehcache.sourceforge.net]
- The BlockingCache uses mutexes to reduce contention.
- Terracotta supports Ehcacheout of the box. Liferay will integrate closely with Terracotta DSO for increased scalability and performance.
- Ehcache has much broader support. The fact that Gavin King (from the Hibernate project) is a committer gives Ehcache much credibility.
- Fine grained configuration for multiple caches. The ability to tune specific cache settings for each object type provides greater flexibility.
Known Limitations:
- Ehcache does not directly support the concept of cache groups to manage dependent objects, so a custom solution was engineered to support this concept.
Migrating from OSCache (pre 4.3.1) to EhCache#
The following properties were removed from portal.properties:
cache.memory=true cache.capacity=10000 cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache cache.blocking=true cache.event.listeners=... cache.cluster.multicast.ip=231.12.21.100 cache.cluster.properties=...
Additionally, the following files were removed from portal-impl.jar:
cache-multi-vm.properties cache-single-vm.properties
Any custom settings you have configured in these properties or files need to be translated to the Ehcache configuration described below.
Ehcache Configuration#
The following section describes Ehcache configuration as it pertains to Liferay. For specific configuration consult the Ehcache documentation.
The following properties have been added to portal.properties:
#
# Set the Hibernate cache provider. Ehcache is recommended in a clustered
# environment. See hibernate.cache.provider_configuration_file_resource_path
# for detailed configuration.
#
hibernate.cache.provider_class=net.sf.ehcache.hibernate.EhCacheProvider #
# This property is used if Hibernate is configured to use Ehcache's
# cache provider.
#
net.sf.ehcache.configurationResourceName=/ehcache/hibernate.xml #
# Set the classpath to the location of the Ehcache config file for internal
# caches. Edit the file specified in the property
# "ehcache.multi-vm.config.location" to enable clustered cache.
#
ehcache.single.vm.config.location=/ehcache/liferay-single-vm.xml
ehcache.multi.vm.config.location=/ehcache/liferay-multi-vm.xmlThe following files have been added to portal-impl.jar. These are used to control specific Ehcache settings:
/ehcache/hibernate.xml
Used for hibernate specific caches. These can be distributed but has been disabled by default.
/ehcache/liferay-single-vm.xml
Used for caches not intended for clustering. Do not try to cluster these caches.
/ehcache/liferay-multi-vm.xml
Used for caches that may be distributed. Clustering has been disabled by default.