[Logo] Terracotta Discussion Forums
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
Element expiring problem  XML
Forum Index -> Ehcache
Author Message
keqdm

neo

Joined: 02/03/2010 04:00:11
Messages: 2
Offline

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.
apaliwal

praetor

Joined: 01/05/2010 20:52:24
Messages: 205
Offline

If an element is expired, its left there. Whenever the expired element is accessed, it is discarded. There is some work going on in this direction to add an evictor, which throws out the element when expired.

Try something like test.get("oggettoProva"); after the element is expired it shall return null.

HTH

cheers
ashish
keqdm

neo

Joined: 02/03/2010 04:00:11
Messages: 2
Offline

I thought it should call the method notifyElementExpired on my rssCacheListener class.
 
Forum Index -> Ehcache
Go to:   
Powered by JForum 2.1.7 © JForum Team