I have a Spring Boot application using Spring Caching annotations. Now I want to migrate to JSR-107 (JCache) annotations.
This is my method:
@Cacheable(value = "results", key = "#input.id")
public CalculatorResult calculate(CalculatorInput input, Operation operation) {
// Code omitted for simplicity
}
And I want my new method something like this:
@CacheResult(cacheName = "results")
public CalculatorResult calculate(@CacheKey CalculatorInput input, Operation operation) {
// Code omitted for simplicity
}
The CalculatorInput class:
public class CalculatorInput {
private String id;
private Double num1;
// Getters and setters omitted for simplicity
}
The @CacheKey annotation instructs spring to store the whole CalculatorInput Object as Key. I would like using as key only the attribute id of CalculatorInput class.
How can I create a cache key (as I did with Spring caching annotation) but using JCache?
Thank you.