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.
Ehcache evicts objects from the cache when one of the following conditions are met:
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.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With