Posts Tagged ‘EHCache’
Liferay Cache
Leveraging Liferay Cache to Improve performance :
Liferay provides out of box Cache MultiVMPool, which can be used by portlets to cache results of heavy network calls i.e. web services.
MultiVMPool Cache is very easy to use and yet powerful enough to work in clustered environment. Unfortunately there is no official documentation for MultiVMPool, which describes how it works and how it can be leverage by portlets.
What is MultiVMPool Cache ?
-
- Out of Box Cache from Liferay : No additional configuration infrastructure needed.
- Wrapper around EHCache : As powerful as EHCache
- Clustered Cache
- JVM Level Cache: Object cached by one WAR will be available to other WARs on same JVM.
How to Use :-
-
- MutliVMPoolUtil : Utility class provides methods to access MultiVMPool
http://docs.liferay.com/portal/5.1/javadocs/portal-kernel/com/liferay/portal/kernel/cache/MultiVMPoolUtil.html - Common Usage :
Using MultiVMPoolUtil : new cache will be dynamically created if not exits.
Following methods shows basic usage :
name= Cache Name
key=Key of Cache Entry
obj=Object to be Cached.
Put Obeject in Cache
put(java.lang.String name, java.lang.String key, java.io.Serializable obj)
Get Object from Cache
get(java.lang.String name, java.lang.String key)
Clear Cache
clear(java.lang.String name)Remove Object from Cache
remove(java.lang.String name, java.lang.String key) Please note here that Liferay MutliVMPoolUtil provides overloaded method to put Normal object (i.e non serialized) also. But in Clustered environment make sure to use Serialized object which can be copied to other caches over wire.
Clustered Cache needs to enable from portal.properties
ehcache.multi.vm.config.location=/ehcache/liferay-multi-vm-clustered.xml
- MutliVMPoolUtil : Utility class provides methods to access MultiVMPool
Pros:
-
- Easy to Use
- No configuration required from portlet
- Clustered Cache
Cons:
-
- Use Default settings for Cache created. No API to set different timeToLive,timeToIdle
settings for the cache. - To change default Cache settings only done using EXT environment.
- Use Default settings for Cache created. No API to set different timeToLive,timeToIdle