//doesn't matter it returns false/true it will set the required headers automatically. //It doesn't include 'Cache-Control:no-cache' so have to do browser F5 if (swr.checkNotModified(resourceService.lastModified())) { //it will return 304 with empty body return null; }
//uncomment the following if last-modified checking is needed at every action /* swr.getResponse().setHeader(HttpHeaders.CACHE_CONTROL, CacheControl.noCache() .getHeaderValue());*/
return resourceService.read(); }
@ResponseBody @RequestMapping(value = "/test2") public ResponseEntity<String> handle2() throws IOException {
//returning ResponseEntity with lastModified, HttpEntityMethodProcessor will //take care of populating/processing the required headers. //As the body can be replaced with empty one and 304 status can be send back, // this approach should be avoided if preparing the response body is very expensive. return ResponseEntity.ok() .lastModified(resourceService.lastModified()) .body(resourceService.read()); }