The example in spring-guides for caching shows how to retrieve one element and store it the cache
@Override
@Cacheable("books")
public Book getByIsbn(String isbn) {
simulateSlowService();
return new Book(isbn, "Some book");
}
I would like to query the DB get the all the elements at once and then store them on startup (PostConstruct) as a reference cache.
public Collection<Book> getAllBooks() {
return this.entityManager.createNamedQuery(Book.all, Book.class).getResultList();
}
Can you store the Map directly? should I call the getAllBooks() method ad use the @CachePut in a BookService.
Could someone give an example/ best practice?
Thanks