When CDI and Inifispan meet you've got the chance to improve your code a lot. Let's combine both to make all of your CDI beans @Cacheable.
Caching of values usually goes this way:
public String getSomething(String input) {
String result = cache.contains(input);
if(result == null) {
result = getValueFromDatabase(input);
cache.put(input, result);
}
return result;
}
This pattern repeats for every value which is cached/retrieved. Methods like the one above contain repetitive conditionals and value retrievals. Using the caching interceptor pattern eliminates the need for repetition. Business methods will be reduced back to their essence and caching becomes an aspect.
@Cacheable
public String getSomething(@CacheKey String input) {
return getValueFromDatabase(input);
}