我想在高速缓存控制头设置最大年龄。我写下如下,但仍然有最大年龄0.我想设置最大年龄只有一种方法,所以我不想禁用默认值。我thik应该ovveride。弹簧控制器没有得到高速缓存控制头
@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知道我做错了什么?
'SpringSecurity'默认设置为'no-cache'模式。您可以在'HttpServletResponse'对象中设置缓存设置。 '@RequestMapping(值= “/”,方法= RequestMethod.GET) \t公共字符串欢迎(HttpServletResponse的响应){ \t \t response.setHeader( “缓存控制”,“无变换,公共,最大年龄= 3600" ); \t \t返回“欢迎”; \t}' – harshavmb
谢谢vaery了。我将它改为: httpServletResponse.setHeader(“Cache-Control”,“no-transform,public,max-age = 3600”); count + = 1; return“Ale ma kota a kot ma ale a count”+ String.valueOf(count); },并作为响应缓存控制→无变换,公共,最大年龄= 3600,但我认为它不起作用。重载次数增加后。 – RafalQA
好的。你如何验证响应缓存头?通过在一个方法中计数并增加它?理想情况下,您应该检查浏览器网络控制台并检查响应头。 https://stackoverflow.com/questions/4423061/view-http-headers-in-google-chrome是链接 – harshavmb