Spring Rest API控制器的缓存响应 [英] Cache response of spring rest api controller

查看:53
本文介绍了Spring Rest API控制器的缓存响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有通过方法参数来缓存spring REST API的响应?例如,在下面的代码中,如果该国家/地区已经被检索过一次,则从缓存中返回相同的响应(json序列化数据).

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

推荐答案

有一个很好的指南展示了如何使用Spring缓存数据.

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.

这篇关于Spring Rest API控制器的缓存响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆