1:Cache-Control 流程
2:不同节点配置
1)spring boot yml
spring:
resources:
static-locations: classpath:/static/,classpath:/views/,classpath:/templates/
chain:
strategy:
#MD5实现
content:
enabled: true
paths: /**
#版本号管理(与MD5实现方式同时存在时,需要指定不同的路径,来分别实现对应的文件管理)
#fixed:
# 开启版本控制策略,默认为false
#enabled: true
#paths: /**,/v1.0.0/**
#version: v1.0.0
cache: true
compressed: false
enabled: true
#缓存
cache:
cachecontrol:
cache-public: true
# 缓存有效期 24小时
max-age: 24h
# 资源缓存时间,单位天,7天
period: 7d
2)spring boot filter
@Component
public class AddResponseHeaderFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
FilterChain filterChain) throws ServletException, IOException {
httpServletResponse.addHeader("X-Frame-Options", "DENY");
httpServletResponse.addHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=0");
httpServletResponse.addHeader("Cache-Control", "no-cache='set-cookie'");
httpServletResponse.addHeader("Pragma", "no-cache");
filterChain.doFilter(httpServletRequest, httpServletResponse);
}
}
3)spring boot filter
public class HttpResponseInterceptorHandler implements HandlerInterceptor {
// 实现HandlerInterceptor 或者 继承HandlerInterceptorAdapter都可以,如果想看着简洁就使用后者
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
response.addHeader("content-test","123");
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
}
}
4)nginx
5)tomcat