我想在响应中设置缓存控制头中的最大年龄。我已经写了如下,但仍然有max-age 0.我想只为一个方法设置最大年龄,所以我不想禁用默认值。我应该是最好的。
@ApiOperation(value = "get value by foreign currency", response = Property.class)
@RequestMapping(method = RequestMethod.GET, value = "/properties/{id}")
@ResponseBody
public ResponseEntity<BigDecimal> getValueByForeignCurrency(@PathVariable Long id,
@RequestParam("currency") String currency, Locale locale) {
if (!ForeignCurrency.isLegalCurrency(currency)) {
throw new IllegalArgumentException("Currency: " + currency + " is not legal");
}
BigDecimal foreignValue = propertyService.getPropertyValueInForeignCurrency(id, currency, locale);
return ResponseEntity.ok().cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS))
.body(foreignValue);
}
Sombody知道我做错了什么?
答案 0 :(得分:1)
SpringSecurity
设置为no-cache
模式。
您可以在HttpServletResponse
对象中设置缓存设置。
@RequestMapping(value = "/", method = RequestMethod.GET)
public String welcome(HttpServletResponse response) {
response.setHeader("Cache-Control", "no-transform, public, max-age=3600");
return "welcome";
}
请参阅this以获取官方文档。