BAEL3771 Review Comments (#8726)

* BAEL3771: Cache Headers in Spring MVC

* BEAL3771: Cache Headers in Spring MVC

* BEAL3771: Cache Headers in Spring MVC

* BAEL:3771 Few review comments
This commit is contained in:
dev-chirag
2020-02-15 22:12:27 +05:30
committed by GitHub
parent 9e421b1247
commit 49cda16d69
3 changed files with 15 additions and 15 deletions
@@ -3,9 +3,8 @@ package com.baeldung.cache;
import org.springframework.http.CacheControl;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.request.WebRequest;
import javax.servlet.http.HttpServletResponse;
@@ -16,28 +15,28 @@ import java.util.concurrent.TimeUnit;
@Controller
public class CacheControlController {
@RequestMapping(value = "/hello/{name}", method = RequestMethod.GET)
public ResponseEntity<String> helloWorld(@PathVariable String name) {
@GetMapping(value = "/hello/{name}")
public ResponseEntity<String> hello(@PathVariable String name) {
CacheControl cacheControl = CacheControl.maxAge(60, TimeUnit.SECONDS)
.noTransform()
.mustRevalidate();
.noTransform()
.mustRevalidate();
return ResponseEntity.ok()
.cacheControl(cacheControl)
.body("Hello " + name);
.cacheControl(cacheControl)
.body("Hello " + name);
}
@RequestMapping(value = "/home/{name}", method = RequestMethod.GET)
@GetMapping(value = "/home/{name}")
public String home(@PathVariable String name, final HttpServletResponse response) {
response.addHeader("Cache-Control", "max-age=60, must-revalidate, no-transform");
return "home";
}
@RequestMapping(value = "/cache/{name}", method = RequestMethod.GET)
@GetMapping(value = "/login/{name}")
public ResponseEntity<String> intercept(@PathVariable String name) {
return ResponseEntity.ok().body("Hello " + name);
}
@RequestMapping(value = "/validate/{name}", method = RequestMethod.GET)
@GetMapping(value = "/productInfo/{name}")
public ResponseEntity<String> validate(@PathVariable String name, WebRequest request) {
ZoneId zoneId = ZoneId.of("GMT");
@@ -35,7 +35,7 @@ public class WebConfig implements WebMvcConfigurer {
WebContentInterceptor interceptor = new WebContentInterceptor();
interceptor.addCacheMapping(CacheControl.maxAge(60, TimeUnit.SECONDS)
.noTransform()
.mustRevalidate(), "/cache/*");
.mustRevalidate(), "/login/*");
registry.addInterceptor(interceptor);
}
}