Hi all, i have a notification problem in Element expiring.
This is my main class :
Code:
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;
import net.sf.ehcache.event.CacheEventListener;
import net.sf.ehcache.event.RegisteredEventListeners;
public class ehCacheTest {
public static void main(String[] args) {
CacheManager singletonManager = CacheManager.create();
Cache test = singletonManager.getCache("rssCache");
RegisteredEventListeners xxx = test.getCacheEventNotificationService();
xxx.registerListener(new rssCacheListener());
Element e = new Element("oggettoProva", "foo");
test.put(e);
while(true) {
try {
Thread.sleep(1000);
System.out.println("e.isExpired() : " + e.isExpired());
} catch (InterruptedException e1) {
}
}
}
}
----
import net.sf.ehcache.CacheException;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import net.sf.ehcache.event.CacheEventListener;
public class rssCacheListener implements CacheEventListener {
public Object clone() throws java.lang.CloneNotSupportedException {
System.out.println("clone");
return null;
}
@Override
public void dispose() {
System.out.println("dispose");
}
@Override
public void notifyElementEvicted(Ehcache ehcache, Element element) {
System.out.println("Element : " + element.getKey() + " evicted" );
}
@Override
public void notifyElementExpired(Ehcache ehcache, Element element) {
System.out.println("Element : " + element.getKey() + " expired" );
}
@Override
public void notifyElementPut(Ehcache ehcache, Element element)
throws CacheException {
System.out.println("NEW ELEMENT" );
}
@Override
public void notifyElementRemoved(Ehcache ehcache, Element element)
throws CacheException {
System.out.println("Element : " + element.getKey() + " removed" );
}
@Override
public void notifyElementUpdated(Ehcache ehcache, Element element)
throws CacheException {
System.out.println("Element : " + element.getKey() + " updated" );
}
@Override
public void notifyRemoveAll(Ehcache ehcache) {
System.out.println("notifyRemoveAll");
}
}
this is output :
Code:
NEW ELEMENT
e.isExpired() : false
e.isExpired() : true
e.isExpired() : true
e.isExpired() : true
e.isExpired() : true
and this is ehcache.xml block:
Code:
<cache name="rssCache"
maxElementsInMemory="10000"
maxElementsOnDisk="0"
eternal="false"
overflowToDisk="false"
timeToLiveSeconds="1"
timeToIdleSeconds="1"
memoryStoreEvictionPolicy="FIFO">
</cache>
So, it correctly notify when i create the Element in cache, but i never receive Element expiry event.
Why?
Tnx, Fabio.