Cache response of spring rest api controller

2019-08-27 04:30发布

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);
     }
}

1条回答
乱世女痞
2楼-- · 2019-08-27 05:13

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.

查看更多
登录 后发表回答