我想: 当两个条件都为真时删除实体
问题: 除超时外,我应该如何暗示其他删除条件?或者我如何从删除侦听器恢复实体(请参阅下面的代码)?
我的代码(已根据超时删除):
LoadingCache<String, Integer> ints = CacheBuilder.newBuilder()
.maximumSize(10000)
.expireAfterAccess(ACCESS_TIMEOUT, TimeUnit.MILLISECONDS)
.removalListener(
new RemovalListener() {
public void onRemoval(RemovalNotification notification) {
if (notification.getCause() == RemovalCause.EXPIRED) {
if (!isExternalCondition()) {
//IS IT POSSIBLE TO RESTORE?
restore(notification.getValue());
}
} else {
System.out.println("Just removed for some reason");
}
}
}
)
.build(
new CacheLoader<String, Integer>() {
public Integer load(String key) throws Exception {
return new Integer(-1);
}
});
答案 0 :(得分:-1)
使用 isExternalCondition ()方法尝试静态类。