在Java中实现写回缓存

在Java中实现写回缓存,java,caching,soft-references,Java,Caching,Soft References,我正在尝试实现回写缓存。我尝试使用软引用,但执行事后回写时遇到问题,因为引用在添加到gcQueue之前被清除,因此我无法访问referent对象 解决方案?您可以试试 例如: final ConcurrentMap<Long, Integer> cache = new MapMaker() .softValues().expiration(20,TimeUnit.MINUTES) .makeComputingMap(new Function<Lo

我正在尝试实现回写缓存。我尝试使用软引用,但执行事后回写时遇到问题,因为引用在添加到gcQueue之前被清除,因此我无法访问referent对象

解决方案?

您可以试试

例如:

final ConcurrentMap<Long, Integer> cache = new MapMaker()
        .softValues().expiration(20,TimeUnit.MINUTES)
        .makeComputingMap(new Function<Long, Integer>() {
              @Override
            public Integer apply(Long arg0) {
                return null;
            }
            });
final ConcurrentMap cache=new MapMaker()
.softValues().过期时间(20,时间单位.分钟)
.makeComputingMap(新函数(){
@凌驾
应用公共整数(长arg0){
返回null;
}
});
关于MapMaker的问题:

可选选项:


使用供应商类,它也是guava库的一部分。

我真的看不出它对写回有什么帮助。