Is there anyway to cache the response of spring REST API by method parameter? For example, in below code, return the same response (the json serialized data) from cache if the country is already retrieved once.
@Controller
public class DataController {
// Can we cache here by country?
@RequestMapping(value = "/api/info/{country}", method = RequestMethod.GET)
public CountryInfo getCountryInfo(@PathVariable("country")String country){
return service.getCountryInfo(country);
}
}
There is a good guide that shows how you can cache data with Spring.
Even though my answer does not include any code, I would recommend taking a look at it. It is a step-by-step guide that I believe can help you with your problem.