【发布时间】:2014-03-26 06:08:06
【问题描述】:
我想要:两个条件都为真时删除实体
- 超时已过
- 一些外部条件为真
问题: 我应该如何暗示除了超时之外的其他移除条件?或者我怎样才能从删除监听器中恢复实体(见下面的代码)?
我的代码(仅基于超时已删除):
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);
}
});
【问题讨论】:
-
如果你能做到这一点,我会很惊讶。
标签: java collections guava