简体   繁体   中英

Cache response of spring rest api controller

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM