使用Spring'配置缓存时出现问题;s ResourceHandlerRegistry
我正在尝试使用Spring的使用Spring'配置缓存时出现问题;s ResourceHandlerRegistry,spring,spring-mvc,caching,browser-cache,cache-control,Spring,Spring Mvc,Caching,Browser Cache,Cache Control,我正在尝试使用Spring的ResourceHandlerRegistry为单页应用程序配置缓存控制 我需要将index.html页面不缓存,并将所有其他类路径资源(已升级的CSS和JS)缓存 以下是我的想法: @Configuration @Profile(Profiles.CLOUD) class CloudWebMvcConfiguration extends WebMvcConfigurerAdapter { private static final int ONE_YEAR
ResourceHandlerRegistry
为单页应用程序配置缓存控制
我需要将index.html
页面不缓存,并将所有其他类路径资源(已升级的CSS和JS)缓存
以下是我的想法:
@Configuration
@Profile(Profiles.CLOUD)
class CloudWebMvcConfiguration extends WebMvcConfigurerAdapter {
private static final int ONE_YEAR = 365 * 24 * 60 * 60;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")//
.addResourceLocations("classpath:/")//
.setCachePeriod(ONE_YEAR);
registry.addResourceHandler("/")//
.addResourceLocations("classpath:/index.html")//
.setCachePeriod(0);
}
}
但是,在chrome控制台中查看响应标题表明index.html
页面也被缓存:
Remote Address:[::1]:5000
Request URL:http://localhost:5000/
Request Method:GET
Status Code:304 Not Modified
Response Headers
view source
Cache-Control:no-cache, no-store, max-age=0, must-revalidate
Date:Wed, 26 Aug 2015 20:09:14 GMT
Expires:0
Last-Modified:Wed, 26 Aug 2015 19:58:27 GMT
Pragma:no-cache
Server:Apache-Coyote/1.1
X-Application-Context:application:cloud:5000
X-Content-Type-Options:nosniff
X-Frame-Options:DENY
X-XSS-Protection:1; mode=block
请参见未修改的304
以下是我如何提供index.html
(它映射到/
):
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/index.html");
}