1
我想在我的Tomcat 6項目中使用EhCache
。我使用的EhCache是1.4版本,因爲它已經在我的Hibernate項目中使用。我已經編寫了自己的自定義CacheEventListener(下面包含),它的工作方式除了notifyElementExpired()
的一個問題。看來notifyElementExpired()
只有在我向緩存中添加其他內容時纔會調用。在旁邊注意,notifyElementPut()
被調用好了。使用CacheEventListener在EhCache中記錄驅逐
有人可以提出一個解決方案嗎?
public class EhCacheEventListener implements CacheEventListener {
private Logger log4j =
LoggerFactory.getLogger(this.getClass().getPackage().getName());
public void notifyElementRemoved(Ehcache cache, Element element) throws CacheException {
log4j.debug("cache element removed---->"+element.getKey());
}
public void notifyElementPut(Ehcache cache, Element element) throws CacheException {
log4j.debug("cache element put---->"+element.getKey());
}
public void notifyElementUpdated(Ehcache cache, Element element) throws CacheException {
log4j.debug("cache element updated---->"+element.getKey());
}
@Override
public void notifyElementExpired(Ehcache cache, Element element) {
//log4j.debug("Element creation time is "+element.getCreationTime());
log4j.debug("cache element expired---->"+element.getKey());
//log4j.debug("Element expiry time is "+element.getExpirationTime());
}
@Override
public void notifyElementEvicted(Ehcache cache, Element element) {
log4j.debug("cache element evicted---->"+element.getKey());
}
public void notifyRemoveAll(Ehcache cache) {}
public void dispose() {}
public Object clone(){
throw new UnsupportedOperationException("Not supported yet.");
}
}