页面缓存是否启用可配置

This commit is contained in:
devezhao 2019-05-07 16:54:44 +08:00
parent c8ca1518d1
commit 47592dcde1
2 changed files with 16 additions and 2 deletions

View file

@ -48,11 +48,23 @@ public class RequestWatchHandler extends HandlerInterceptorAdapter {
private static final Log LOG = LogFactory.getLog(RequestWatchHandler.class);
// 设置页面无缓存
// 如果使用了第三方缓存策略 nginx etag可以将此值设为 false
private boolean noCache = true;
public void setNoCache(boolean noCache) {
this.noCache = noCache;
}
public boolean isNoCache() {
return noCache;
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {
response.setCharacterEncoding("utf-8");
if (!ServletUtils.isAjaxRequest(request)) {
if (noCache && !ServletUtils.isAjaxRequest(request)) {
ServletUtils.setNoCacheHeaders(response);
}

View file

@ -25,7 +25,9 @@
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**" />
<bean class="com.rebuild.web.RequestWatchHandler"></bean>
<bean class="com.rebuild.web.RequestWatchHandler">
<property name="noCache" value="true" />
</bean>
</mvc:interceptor>
</mvc:interceptors>