Reputation: 10530
I have below configuration in my project
<defaultCache maxElementsInMemory="100" eternal="false" overflowToDisk="false" memoryStoreEvictionPolicy="LRU" statistics="false" />
<cache name="customerList" maxElementsInMemory="1000" eternal="false" overflowToDisk="false" memoryStoreEvictionPolicy="LRU" />
As per my understanding eternal =true
attribute explains cache will never expire. But when i mention eternal =false
, how long cache will remain active?
Also i have mentioned maxElementsInMemory=1000
, what will happen when i have more than 1000 elements to put in cache. Will not they be stored in cache and discarded ?
Upvotes: 0
Views: 16456
Reputation: 466
I'm very late to answer this question. But as i have also gone through this issue so want to share my experience.
Hi @emilly, I'm answering specifically to your questions and we will use config. that is shared by @RCB.
<cache name="customerList" maxElementsInMemory="1000" eternal="false" timeToLiveSeconds="60" overflowToDisk="false" memoryStoreEvictionPolicy="LRU" />
Question 1:
As timeToLiveSeconds="60" so it's the maximum time for which "customerList" data will be there in cache(L2). Cache Eviction is not directly related to the value of this attribute(timeToLiveSeconds).
e.g. If customerList is created on 12:00:00, it will be available till 12:00:59.
Question 2: say I want to add one more element after 1000. I cache will evict least recently used one and stored the latest element in list as I mentioned memoryStoreEvictionPolicy. Is that right ?
yes, this is the cache(L2) eviction and it will be according to the memoryStoreEvictionPolicy="LRU" and in this example it will a valid operation before TTL(60 seconds).
Upvotes: 0
Reputation: 14500
These two configuration options relate to two fundamental caching concepts:
Upvotes: 2
Reputation: 845
When eternal is false, you can control how long items stay in cache by using the timeToLiveSeconds
attribute. For example, for items to expire after 1 minute:
<cache name="customerList" maxElementsInMemory="1000" eternal="false" timeToLiveSeconds="60" overflowToDisk="false" memoryStoreEvictionPolicy="LRU" />
If you have more than 1000 items and have specified maxElementsInMemory=1000
, then only 1000 of them will be stored in cache. maxElementsInMemory
is an upper limit.
Upvotes: 0