2

Can I connect LoadingCache with a @Cacheable method.

I need GuavaCache to support refreshAfterWrite

return new GuavaCache("cacheName", CacheBuilder.newBuilder()
                .maximumSize(maxSize)
                .expireAfterWrite(expireAfterWriteInSeconds, TimeUnit.SECONDS)
                .ticker(ticker)
                .build());

to

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);
                            }
                        }
                );
    }

but I don't understand how to connect this LoadingCache with a Spring Cache declaration @Cacheable("cacheName")

Alexandre Dupriez
  • 3,026
  • 20
  • 25
  • [This tutorial](https://dzone.com/articles/spring-caching-abstraction-and) may help you integrate the Guava cache with Spring's caching abstraction. This should be possible with a [`CacheManager`](https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/cache/CacheManager.html) – Alexandre Dupriez Mar 21 '18 at 09:55
  • yes but I specifically need to use LoadingCache, not GuavaCache – Joyal Augustine Mar 21 '18 at 10:36

0 Answers0