Is it possible to use spring property placeholders in the unless expression of the @Cacheable annotation? I have a service method I would like cached unless the result returned is less than the value the property minCacheCalc specified in @PropertySource("classpath:application.properties").
Here is the service class method I want to cache:
@Service
class CalculationService {
// @Cacheable(cacheNames="calculations", unless="#result < 10") // works fine hardcoded
@Cacheable(cacheNames="calculations", unless="#result < ${minCacheCalc}")
public Integer calculate(Integer i) {
System.out.println("calculate(" + i + ")");
return i * i - i;
}
}
Calls to this throw the error:
SpelParseException: EL1041E: After parsing a valid expression, there is still more data in the expression: 'lcurly({)'
I have tried many variations of syntax but I can't seem to find one.
Is there a way to reference a property in my @Cacheable's unless parameter?