How caching declaration is done for LoadingCache

539 Views Asked by At

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")

0

There are 0 best solutions below