Total Pageviews

Monday, May 21, 2012

Liferay Cache - ehcache


Liferay internally uses EhCache for implementing cache for the database. However it is possible to implement ehcache in our custom code.
You can see the additional knowledge about it here.
But this how the liferay caches the database it is using. Apart form this, we can also use ehcache for our custom implementation. Lets see how this can be done:
Here we have two function setting and getting values in cache. We can import the class and use in our code.
Hope this will help.

4 comments:

  1. Hello Apoorva,
    I am trying this example to implement caching. But I am getting an exception for the code -
    element.SetTimeToLive(CACHE_EXPERIATION_TIME)

    "The method setTimeToLive(int) is undefined for the type Element"
    Do you have quick fix for this?

    ReplyDelete
    Replies
    1. Hi Srinath,

      See the API here. http://ehcache.org/apidocs/net/sf/ehcache/Element.html

      Regards,
      Apoorva

      Delete
  2. Hi Apoorva,
    Can we use this in clustered environment ?

    ReplyDelete