Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebApp Session Management using Ehcache

In my project I am using ehcache to store loggged in user details and some other information (which app will use this at runtime instead of fetching from db). The following is my ehcache configuration:

<cache 
    name="normalCache"
    maxElementsInMemory="50000" 
    eternal="false"
    timeToIdleSeconds="1800" 
    timeToLiveSeconds="0"
    overflowToDisk="false"
    memoryStoreEvictionPolicy="LRU"
/>

But the problem is most of the time session timeout happening (even user is not inactive more >30). Sometimes its happening for 10 mins,...

All the actions will try to retrieve user object per each request from the ehcache.

I am not sure how ehcache will determine expiry time.

like image 748
Ramki Avatar asked Oct 09 '11 03:10

Ramki


1 Answers

Ehcache evicts objects from the cache when one of the following conditions are met:

  1. Object has not been accessed from ehcache (read or updated) for more than timeToIdle seconds. This rule does not apply if timeToIdle is not set. In other words, an object is qualified to remain in the cache for infinite time even if it is never accessed (read or updated) from the cache when timeToIdle is not set.

  2. Object has been in the cache for more than timeToLive seconds. This rule does not apply if timeToLive is not set. In other words, an object is qualified to remain in the cache for infinite time.

  3. Number of items in the cache has reached maxElementsInMemory limit. In that case memoryStoreEvictionPolicy comes into action and removes the elements matching the eviction policy until the number of elements in the cache becomes less than maxElementsInMemory limit, even though those items are qualified to be in the cache as per condition No. 1 and No. 2.

Hope that clarifies it!

like image 119
RaviH Avatar answered Sep 22 '22 02:09

RaviH