Make EHCache expire elements which have not been accessed in a specific way
I'm trying to get EHCache to mark cache elements as expired if they have not been accessed in a开发者_StackOverflow社区 particular way, within a specified amount of time.
I have an automated cache-refresher which should refresh elements in the cache without updating the last-accessed time. It runs on a regular schedule. However, if a user requests something from the cache through the application, then the last-accessed time should be updated. Elements should expire and be removed from the cache after a week of user inactivity.
Does EHCache have anything already in-place that would solve this sort of problem? I see the putQuiet and getQuiet methods, but I don't see any explicit mention of them not updating the last-accessed time. Also, is there any real difference between the timeToLiveSeconds and timeToIdleSeconds parameters?
Thanks, Mike
timeToIdleSeconds:
Sets the time to idle for an element before it expires.
i.e. The maximum amount of time between accesses before an element expires
Is only used if the element is not eternal.
Optional attribute. A value of 0 means that an Element can idle for infinity.
The default value is 0.
timeToLiveSeconds:
Sets the time to live for an element before it expires.
i.e. The maximum time between creation time and when an element expires.
Is only used if the element is not eternal.
Optional attribute. A value of 0 means that and Element can live for infinity.
The default value is 0.
for other attributes refer the ehcache.xml that ships with the ehcache package. you can instantiate your cache with the Cache construtor with the parameters then the cache will manage this on its own
精彩评论