Created
November 13, 2024 04:05
-
-
Save guaracyalima/dfff9876b2710289512967fa70f4dd11 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.zeroth.zth_product_srv.config; | |
import jakarta.servlet.http.HttpServletRequest; | |
import jakarta.servlet.http.HttpServletResponse; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.web.servlet.HandlerInterceptor; | |
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |
import java.util.concurrent.TimeUnit; | |
@Configuration | |
public class ApiCacheConfig implements WebMvcConfigurer { | |
@Override | |
public void addInterceptors(InterceptorRegistry registry){ | |
registry.addInterceptor( | |
new CacheControlInterceptor()); | |
} | |
private static class CacheControlInterceptor implements HandlerInterceptor{ | |
@Override | |
public boolean preHandle(HttpServletRequest request, | |
HttpServletResponse response, Object handler){ | |
response.setHeader( | |
"Cache-Control", | |
"public max-age="+ | |
TimeUnit.HOURS.toSeconds(1)); | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment