I'm using spring-cache to improve database queries, which works fine as follows:
@Bean
public CacheManager cacheManager() {
return new ConcurrentMapCacheManager("books");
}
@Cacheable("books")
public Book getByIsbn(String isbn) {
return dao.findByIsbn(isbn);
}
But now I want to prepopulate the full book-cache on startup. Which means I want to call dao.findAll()
and put all values into the cache. This routine shall than only be scheduled periodically.
But how can I explicit populate a cache when using @Cacheable
?