Spring cache: custom key generator (#4166)

This commit is contained in:
Felipe Santiago Corro
2018-05-05 02:40:37 -03:00
committed by maibin
parent 258d5c09f0
commit e22750ffe1
4 changed files with 76 additions and 0 deletions
@@ -0,0 +1,21 @@
package com.baeldung.cache;
import com.baeldung.model.Book;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
@Component
public class BookService {
@Cacheable(value="books", keyGenerator="customKeyGenerator")
public List<Book> getBooks() {
List<Book> books = new ArrayList<Book>();
books.add(new Book(1, "The Counterfeiters", "André Gide"));
books.add(new Book(2, "Peer Gynt and Hedda Gabler", "Henrik Ibsen"));
return books;
}
}