I have a couple of beans defined with java @Configuration
. Some of them have methods perform pretty long calculations and I'd like to cache returned values for given arguments to avoid making those calculations every time a method is called.
Example:
@Configuration public class Config {
@Bean public CalculatorBean calcBean() {
return new CalculatorBean();
}
}
public class CalculatorBean {
public int hugeCalculation(int arg1, String arg2, double[] arg3) {
// ... very long calculation ...
}
}
Ideally, I'd like to annotate @Bean
methods in @Configuration
with some kind of custom @Cached(method="hugeCalculation", size=1000, ttl=36000)
and have bean factory automatically post-processed to wrap those beans in AOP proxies.
Are there any ready solutions of this kind? If not, what classes of Spring should I use to do this?