I'm trying to add caching on my spring-boot app by following instruction on https://www.java4s.com/spring-boot-tutorials/how-to-configure-cache-in-spring-boot-applications/, but it doesn't work. I'm not entirely sure how to test it. I have a system.out.print under controller like in this article. If cache works then it will print "test" only once but return the same result from the request with same input. I have my code as below:
CurrencyController.java
@RequestMapping(method = RequestMethod.POST)
@Cacheable(value="currency")
public ResponseEntity getExchangedCurrency(final @RequestBody CurrencyExchange currencyExchange) {
System.out.println("Test");
return ResponseEntity.ok()
.headers(responseHeaders)
.body(currencyService.calculate(currencyExchange));
}
App.java
@SpringBootApplication
@EnableCaching
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}