我是 JBossCache 的新手。阅读用户文档,它说可以将侦听器添加到使用的 Eviction 类中,但我无法找到如何将一个侦听器添加到配置文件,或者应该如何添加。
我尝试使用@NodeEvicted 方法添加@CacheListener,但该方法
@CacheListener
public class EvictionListener {
@NodeEvicted
public void nodeEvicted(NodeEvent ne) {
System.out.println("Se borro el nodo");
}
}
并将其添加到缓存实例
CacheFactory factory = new DefaultCacheFactory();
this.cache = factory.createCache();
EvictionListener listener = new EvictionListener();
this.cache.create();
this.cache.addCacheListener(listener);
但系统输出未执行。为了测试它,我只是运行一个简单的 Main 值。这是我正在使用的配置值:
<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:jboss:jbosscache-core:config:3.2">
<transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<eviction wakeUpInterval="20">
<default algorithmClass="org.jboss.cache.eviction.FIFOAlgorithm" wakeUpInterval="20">
<property name="maxNodes" value="20" />
</default>
</eviction>
</jbosscache>