2

我可以连接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")

4

0 回答 0