gpt4 book ai didi

java - Guava 缓存生成器 : imply additional conditions to entity removal

转载 作者:行者123 更新时间:2023-12-02 09:36:16 25 4
gpt4 key购买 nike

我想要:当两个条件都成立时删除实体

  • 超时已过
  • 某些外部条件成立

问题: 除了超时之外,我应该如何暗示其他删除条件?或者如何从删除监听器恢复实体(参见下面的代码)?

我的代码(已仅根据超时删除):

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com