I would like my Spring controller to cache the returned content. I found a lot of questions on how to disable caching. I would like to know how to enable caching. My controller is as follows:
@Controller public class SimpleController { @RequestMapping("/webpage.htm") public ModelAndView webpage(HttpServletRequest request, HttpServletResponse response) { ModelAndView mav = new ModelAndView("webpage"); httpServletResponse.setHeader("Cache-Control", "public");
As you can see, I added the line: httpServletResponse.setHeader("Cache-Control", "public"); to set caching, but in my browser, when I refresh this page, I still get the same result: 200 OK . How can I achieve a result of 304 not modified ? I can set the @ResponseStatus(value = HttpStatus.NOT_MODIFIED) annotation @ResponseStatus(value = HttpStatus.NOT_MODIFIED) for this method, but will it only be status or also actual caching?
source share