How to enable HTTP response caching in Spring Boot

前端 未结 8 1931
我寻月下人不归
我寻月下人不归 2020-11-27 12:17

I have implemented a REST server using Spring Boot 1.0.2. I\'m having trouble preventing Spring from setting HTTP headers that disable HTTP caching.

My controller is

8条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 13:03

    Overriding of default caching behavior for a particular method can be done in the below way:

    @Controller
    public class MyRestController {
        @RequestMapping(value = "/someUrl", method = RequestMethod.GET)
        public @ResponseBody ResponseEntity myMethod(
                HttpServletResponse httpResponse) throws SQLException {
            return new ResponseEntity.ok().cacheControl(CacheControl.maxAge(100, TimeUnit.SECONDS)).body(T)
        }
    }
    

提交回复
热议问题