I have a CacheEventListener of ehcache3 and I have set ttl time 30 sec after 30 the listener is not calling automatically
Below is my ehcache.xml file
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.ehcache.org/v3"
xmlns:jsr107="http://www.ehcache.org/v3/jsr107"
xsi:schemaLocation="
http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">
<cache alias="cacheFiles">
<key-type>java.lang.String</key-type>
<value-type>java.util.List</value-type>
<expiry>
<ttl unit="seconds">30</ttl>
</expiry>
<listeners>
<listener>
<class>com.cacheabstraction.listener.CacheEventLogger</class>
<event-firing-mode>ASYNCHRONOUS</event-firing-mode>
<event-ordering-mode>UNORDERED</event-ordering-mode>
<events-to-fire-on>CREATED</events-to-fire-on>
<events-to-fire-on>UPDATED</events-to-fire-on>
<events-to-fire-on>EXPIRED</events-to-fire-on>
<events-to-fire-on>REMOVED</events-to-fire-on>
<events-to-fire-on>EVICTED</events-to-fire-on>
</listener>
</listeners>
<resources>
<heap unit="entries">2</heap>
<offheap unit="MB">10</offheap>
</resources>
</cache>
</config>
and this is my listener class
`public class CacheEventLogger implements CacheEventListener<Object, Object> {
@Override
public void onEvent(CacheEvent<? extends Object, ? extends Object> event) {
if (event.getType() == EventType.EXPIRED && event.getOldValue() != null) {
System.out.println("TTL expired for key: " + event.getKey());
// Add your logic to handle TTL expiration event here
}
}`
Tried multiple way but still the Cache Even Listener is not running automatically
New contributor
PritiRanjan Swain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.