How to change a EhCache members expiry time programmatically

守給你的承諾、 提交于 2019-12-05 20:00:52

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

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

In Ehcache 3.x, you can implement a custom Expiry and have it return different Duration depending on the key and value:

public interface Expiry<K, V> {
  Duration getExpiryForCreation(K key, V value);
  Duration getExpiryForAccess(K key, ValueSupplier<? extends V> value);
  Duration getExpiryForUpdate(K key, ValueSupplier<? extends V> oldValue, V newValue);
}

Check the API documentation for more information.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!