简体   繁体   English

Spring Rest API控制器的缓存响应

[英]Cache response of spring rest api controller

Is there anyway to cache the response of spring REST API by method parameter? 无论如何,是否有通过方法参数来缓存Spring REST API的响应? For example, in below code, return the same response (the json serialized data) from cache if the country is already retrieved once. 例如,在下面的代码中,如果国家/地区已经被检索一次,则从缓存返回相同的响应(json序列化数据)。

@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. 有一个很好的指南显示了如何使用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. 我相信这是一个循序渐进的指南,可以帮助您解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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