Skip to content

Commit d80537a

Browse files
authored
Merge pull request apolloconfig#1535 from nobodyiam/adjust-cache-control
adjust cache control so that entry htmls are not cached, as we need them to trigger 302 in case user is not logged in
2 parents a27bb73 + 2a537f4 commit d80537a

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/WebMvcConfig.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.springframework.http.MediaType;
1010
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
1111
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
12+
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
1213
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
1314

1415
import java.util.List;
@@ -37,4 +38,21 @@ public void customize(TomcatServletWebServerFactory factory) {
3738
mappings.add("html", "text/html;charset=utf-8");
3839
factory.setMimeMappings(mappings );
3940
}
41+
42+
@Override
43+
public void addResourceHandlers(ResourceHandlerRegistry registry) {
44+
// 10 days
45+
addCacheControl(registry, "img", 864000);
46+
addCacheControl(registry, "vendor", 864000);
47+
// 1 day
48+
addCacheControl(registry, "scripts", 86400);
49+
addCacheControl(registry, "styles", 86400);
50+
addCacheControl(registry, "views", 86400);
51+
}
52+
53+
private void addCacheControl(ResourceHandlerRegistry registry, String folder, int cachePeriod) {
54+
registry.addResourceHandler(String.format("/%s/**", folder))
55+
.addResourceLocations(String.format("classpath:/static/%s/", folder))
56+
.setCachePeriod(cachePeriod);
57+
}
4058
}

apollo-portal/src/main/resources/application.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ spring:
33
name: apollo-portal
44
profiles:
55
active: ${apollo_profile}
6-
resources:
7-
cache:
8-
cachecontrol:
9-
max-age: 3600
106

117
server:
128
port: 8080
9+
compression:
10+
enabled: true
1311

1412
logging:
1513
file: /opt/logs/100003173/apollo-portal.log

0 commit comments

Comments
 (0)