// Cache for an hour - "Cache-Control: max-age=3600"CacheControlccCacheOneHour=CacheControl.maxAge(1,TimeUnit.HOURS);// Prevent caching - "Cache-Control: no-store"CacheControlccNoStore=CacheControl.noStore();// Cache for ten days in public and private caches,// public caches should not transform the response// "Cache-Control: max-age=864000, public, no-transform"CacheControlccCustom=CacheControl.maxAge(10,TimeUnit.DAYS).noTransform().cachePublic();
@GetMapping("/book/{id}")
public ResponseEntity<Book> showBook(@PathVariable Long id) {
Book book = findBook(id);
String version = book.getVersion();
return ResponseEntity
.ok()
.cacheControl(CacheControl.maxAge(30, TimeUnit.DAYS))
.eTag(version) // lastModified is also available
.body(book);
}
@RequestMapping
public String myHandleMethod(WebRequest webRequest, Model model) {
long eTag = ...
if (request.checkNotModified(eTag)) {
return null;
}
model.addAttribute(...);
return "myViewName";
}