Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EhCache - remove expired element (because of timeToIdleSeconds or timeToLiveSeconds) without try to get it?

Tags:

ehcache

The EhCache documentation says:

  • Accessing an entry in myCache that has been idle for more than an hour (timeToIdleSeconds) causes that element to be evicted.
  • If an entry expires but is not accessed, and no resource constraints force eviction, then the expired entry remains in place.
  • getting an expired element will remove it from the cache and return null.

If you implement and register a CacheEventListener to receive that an element is expired, you can see the event is fired when you try to get an expired element, but not after the 'timeToIdleSeconds'.

Is it possible to force removing the expired element after it is expired? Because in my case after this time no one will try to get it again.

Thank you.

like image 584
gfjr Avatar asked Sep 06 '13 14:09

gfjr


1 Answers

I've done it with the following code:

cache.evictExpiredElements();
cache.flush();
like image 148
skayred Avatar answered Jan 04 '23 00:01

skayred