2011-11-05 56 views
1

我们的网站运行tomcat和apache,并希望缓存仅在Apache级别的特定jpg,gif图像以减少tomcat负载。Apache缓存特定图像和css

关于CSS和Javascripts,它们都可以被缓存。

在部署更改的图像时,应该自动加载css和javascripts。

我想获得这个配置,但找不到任何..可以有人请分享示例配置?

对于我们来说只缓存特定的图像是非常重要的,它也是非常重要的。

回答

1

在Tomcat应用程序的context.xml添加:

disableCacheProxy="false" securePagesWithPragma="false" 

其次是以下任何一种:

1.使用JSP:

  • 创建一个新的JSP如。 “nocache.jsp” 与以下内容:

    <meta http-equiv="pragma" content="no-cache"> 
    <meta http-equiv="Cache-Control" content="no-store"> <!-- HTTP 1.1 --> 
    <meta http-equiv="Expires" content="0"> 
    
  • 包含此JSP中的所有JSP的其中U不想为缓存:

    <jsp:include page="../nocache.jsp" />

2.使用过滤器:

  • 创建一个新的Filter类 - “CacheHeaderFilter”来处理类不被下面缓存:

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { 
        HttpServletResponse httpResponse = (HttpServletResponse)response; 
        httpResponse.setHeader("Cache-Control","no-cache"); 
        httpResponse.setHeader("Pragma","no-cache"); 
        httpResponse.setDateHeader ("Expires", 0); 
        filterChain.doFilter(request, response); 
    } 
    
  • 在应用的web.xml,配置此过滤器,并指定URL的未进行如下缓存:

    <filter> 
        <filter-name>CacheFilter</filter-name> 
        <filter-class>com.org.CacheHeaderFilter</filter-class> 
    </filter> 
    
    <filter-mapping> 
        <filter-name>CacheFilter</filter-name> 
        <url-pattern>*.action</url-pattern> 
    </filter-mapping>` 
    
+0

非常感谢。 。会试着去看看它是怎么回事.. – user1030627