如何为LoadingCache完成缓存声明

时间:2018-03-21 09:23:47

标签: java spring caching guava google-guava-cache

我可以使用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")

联系起来

0 个答案:

没有答案