我可以使用LoadingCache
方法连接@Cacheable
。
我需要GuavaCache来支持refreshAfterWrite
return new GuavaCache("cacheName", CacheBuilder.newBuilder()
.maximumSize(maxSize)
.expireAfterWrite(expireAfterWriteInSeconds, TimeUnit.SECONDS)
.ticker(ticker)
.build());
到
return CacheBuilder.newBuilder()
.maximumSize(maxSize)
.refreshAfterWrite(refreshAfterWriteInSeconds, TimeUnit.SECONDS)
.build(
new CacheLoader<Integer, List<Type>>() {
@Override
public List<Type> load(Integer id) {
return service.getServiceItem(id);
}
}
);
}
但我不明白如何将此LoadingCache
与Spring Cache声明@Cacheable("cacheName")