Very easy:
<filter>
<filter-name>BrowserCache</filter-name>
<filter-class>com.bla.CacheFilter</filter-class>
<init-param>
<param-name>Cache-Control</param-name>
<param-value>private,max-age=3600</param-value>
</init-param>
<init-param>
<param-name>Pragma</param-name>
<param-value>cache</param-value><!--store on proxies-->
</init-param>
</filter>
<filter-mapping>
<filter-name>BrowserCache</filter-name>
<url-pattern>*.gif</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>BrowserCache</filter-name>
<url-pattern>*.jpg</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>BrowserCache</filter-name>
<url-pattern>*.js</url-pattern>
</filter-mapping>
public class CacheFilter implements Filter {
private FilterConfig filterConfig;
public void init(FilterConfig filterConfig) {
this.filterConfig = filterConfig;
}
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain filterChain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
Enumeration enu = this.filterConfig.getInitParameterNames();
while ( enu.hasMoreElements() ) {
String headerName = (String) enu.nextElement();
response.setHeader(headerName,
filterConfig.getInitParameter(headerName));
//use addHeader so multiple headers can be added...
//BUT: Tomcat adds response no-cache headers to protected
pages to prevent them from being cached by proxy servers.
//--> Images arent cached anymore
//--> Alternative: Use WebServer to server static content
//response.addHeader(headerName,
filterConfig.getInitParameter(headerName));
}
// pass the request/response on to the rest of the filters
filterChain.doFilter(req, response);
}
}
Michael
-----Original Message-----
From: Daniel Niklas [mailto:[EMAIL PROTECTED]
Sent: Freitag, 1. Februar 2008 14:22
To: [email protected]
Subject: Need Filter that caches resources - a more general Extensions
Filter?
Hi,
i need a filter that adds Cache-control to the response-header. I want
to
configure this out for pictures, javascript files and other resources.
Do you know something like this in myfaces or somewhere else? I can't
believe, that i have to write my own implementation of such a filter!?
Best regards
Daniel Niklas
--
View this message in context:
http://www.nabble.com/Need-Filter-that-caches-resources---a-more-general
-Extensions-Filter--tp15226545p15226545.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.