我想要:当两个条件都成立时删除实体
- 超时已过
- 某些外部条件成立
问题: 除了超时之外,我应该如何暗示其他删除条件?或者如何从删除监听器恢复实体(参见下面的代码)?
我的代码(已仅根据超时删除):
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);
}
});
最佳答案
尝试使用 isExternalCondition() 方法的静态类。
关于java - Guava 缓存生成器 : imply additional conditions to entity removal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21990133/