Java 将LoadingCache与CacheManager一起使用
我将下一个用于自定义缓存管理器:Java 将LoadingCache与CacheManager一起使用,java,spring,caching,guava,cachemanager,Java,Spring,Caching,Guava,Cachemanager,我将下一个用于自定义缓存管理器: SimpleCacheManager cacheManager = new SimpleCacheManager(); GuavaCache myCache = new GuavaCache("telescope", CacheBuilder.newBuilder() .expireAfterWrite(5, TimeUnit.MINUTES).build()); cacheManager.setCaches(Arrays.asL
SimpleCacheManager cacheManager = new SimpleCacheManager();
GuavaCache myCache = new GuavaCache("telescope", CacheBuilder.newBuilder()
.expireAfterWrite(5, TimeUnit.MINUTES).build());
cacheManager.setCaches(Arrays.asList(myCache));
return cacheManager;
现在我想使用LoadingCache,因为我需要方法refreshAfterWrite(5,TimeUnit.MINUTES)
而不是expireAfterWrite(5,TimeUnit.MINUTES)
我无法将LoadingCache放入GuavaCache,然后将此GuavaCache设置为SimpleCacheManager
我需要使用哪些实现?为什么不能将
LoadingCache
传递给GuavaCache
?快速阅读GuavaCache
的[javadoc]说明它需要com.google.common.cache.cache
来扩展LoadingCache
的功能。使用CaffeinCache代替GuavaCache。您可以在缓存管理器中设置它们,还可以对它们进行刷新后写入。