0

I would like to set the expiry time of a member of an cache. I want the custom ttl when the object should expire. I know I can set it for the whole cache, e.g.

Cache cache = manager.getCache("MyCache");
CacheConfiguration config = cache.getCacheConfiguration();
config.setTimeToIdleSeconds(60);
config.setTimeToLiveSeconds(120);
config.setMaxEntriesLocalHeap(10000);
config.setMaxEntriesLocalDisk(1000000);

In Ehcache 2.x, We can set expiry time on the Element we insert in the cache:

Element element = new Element("key1", "value1"); element.setTimeToLive(100);

Do we have any other java open source library like that support similar feature as above as Ehcache 3.x doesnot support this.

Ideally I would like to have the following interface:

put(key, value, timeToLive)// enter a key and value with a specified timeToLIve(ttl)

put(key, value) // enter a key value with no timeToLive

anand
  • 1
  • 1
  • Caffeine has a [callback](https://github.com/ben-manes/caffeine/wiki/Eviction#time-based) approach to favor loading through the cache. That also let’s you can use the additional methods in [Cache.policy()](https://www.javadoc.io/doc/com.github.ben-manes.caffeine/caffeine/latest/com.github.benmanes.caffeine/com/github/benmanes/caffeine/cache/Policy.VarExpiration.html) such as your put method. – Ben Manes Mar 24 '23 at 04:19
  • Have you looked at https://www.ehcache.org/documentation/3.0/expiry.html and https://www.ehcache.org/documentation/3.0/eviction-advisor.html? – tgdavies Mar 24 '23 at 04:26

0 Answers0