系统资源,js、图片缓存,提高系统运行速度

1、在web.xml配置

	<filter>
		<filter-name>CacheForWeek</filter-name>
		<filter-class>
			com.sencloud.dh.core.web.filter.ResponseHeaderFilter
		</filter-class>
		<init-param>
			<param-name>Cache-Control</param-name>
			<param-value>max-age=604800, public</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>CacheForWeek</filter-name>
		<url-pattern>/images/*</url-pattern>
	</filter-mapping>
	<filter-mapping>
		<filter-name>CacheForWeek</filter-name>
		<url-pattern>/ext3/*</url-pattern>
	</filter-mapping>
	<filter-mapping>
		<filter-name>CacheForWeek</filter-name>
		<url-pattern>/js/*</url-pattern>
	</filter-mapping>
	<filter-mapping>
		<filter-name>CacheForWeek</filter-name>
		<url-pattern>/css/*</url-pattern>
	</filter-mapping>
2、java代码


/**
 * 
 * @author xutianlong
 * @version [版本号, Sep 11, 2012]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class ResponseHeaderFilter implements Filter
{
    private FilterConfig fc;

    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,
            ServletException
    {
        HttpServletResponse response = (HttpServletResponse) res;

        for (Enumeration e = this.fc.getInitParameterNames(); e.hasMoreElements();)
        {
            String headerName = (String) e.nextElement();
            response.addHeader(headerName, this.fc.getInitParameter(headerName));
        }

        chain.doFilter(req, response);
    }

    public void init(FilterConfig filterConfig)
    {
        this.fc = filterConfig;
    }

    public void destroy()
    {
        this.fc = null;
    }
}

3、主要在项目运行期间使用,提升的速度也还是不错的。主要在
<param-value>max-age=604800, public</param-value>

可以设置js/css/image的过期时间。


你可能感兴趣的:(系统资源,js、图片缓存,提高系统运行速度)