Spring MVC WebContentInterceptor no-cache for static content

时间:2017-04-25 14:16:48

标签: spring spring-mvc caching

使用WebContentInterceptor我在客户端启用了缓存机制。

但正如您所看到的,parent(resources /)文件夹下的某些文件夹应该是  被缓存,其他一些人不应该......

起初我刚刚使用过此配置;

<mvc:interceptor>
        <mvc:mapping path="/resources/**" />

        <mvc:exclude-mapping path="/resources/js/project/**" />
        <mvc:exclude-mapping path="/resources/css/project/**" />
        <mvc:exclude-mapping path="/resources/images/users/**" />

        <bean id="webContentInterceptor"
            class="org.springframework.web.servlet.mvc.WebContentInterceptor">
            <property name="cacheSeconds" value="2592000" />
            <property name="useExpiresHeader" value="true" />
            <property name="useCacheControlHeader" value="true" />
            <property name="useCacheControlNoStore" value="true" />
        </bean>
    </mvc:interceptor>

正如你可以遵循我的逻辑,我已经缓存了所有文件夹,但排除了那些不需要的文件夹。 但它没有用。所以我配置了这样的东西。

<mvc:interceptor>
        <mvc:mapping path="/resources/js/project/**" />
        <mvc:mapping path="/resources/css/project/**" />
        <mvc:mapping path="/resources/images/users/**" />

        <bean id="webContentInterceptorNoCache"
            class="org.springframework.web.servlet.mvc.WebContentInterceptor">
            <property name="cacheSeconds" value="0" />
            <property name="useExpiresHeader" value="true" />
            <property name="useCacheControlHeader" value="true" />
            <property name="useCacheControlNoStore" value="true" />
        </bean>
    </mvc:interceptor>
    <mvc:interceptor>
        <mvc:mapping path="/resources/**" />

        <mvc:exclude-mapping path="/resources/js/project/**" />
        <mvc:exclude-mapping path="/resources/css/project/**" />
        <mvc:exclude-mapping path="/resources/images/users/**" />

        <bean id="webContentInterceptor"
            class="org.springframework.web.servlet.mvc.WebContentInterceptor">
            <property name="cacheSeconds" value="2592000" />
            <property name="useExpiresHeader" value="true" />
            <property name="useCacheControlHeader" value="true" />
            <property name="useCacheControlNoStore" value="true" />
        </bean>
    </mvc:interceptor>

认为第一个拦截器可以删除缓存。但它也没有用。

我甚至试过这个看到无缓存标题

 <mvc:interceptor>
        <mvc:mapping path="/resources/**" />

        <bean id="webContentInterceptor"
            class="org.springframework.web.servlet.mvc.WebContentInterceptor">
            <property name="cacheSeconds" value="0" />
            <property name="useExpiresHeader" value="true" />
            <property name="useCacheControlHeader" value="true" />
            <property name="useCacheControlNoStore" value="true" />
        </bean>
    </mvc:interceptor>

仍然没有机会。

我做错了吗?你能救我吗?

0 个答案:

没有答案