com.caucho.filters
Class AnonymousExpiresFilter

java.lang.Object
  extended by com.caucho.filters.AnonymousExpiresFilter
All Implemented Interfaces:
Filter

public class AnonymousExpiresFilter
extends java.lang.Object
implements Filter

Caches the servlet output for anonymous users. This filter adds an Expires header and the Cache-Control: x-anonymous header.

Requests from anonymous users, i.e. users with no JSESSIONID cookie or ;jsessionid= URL-rewriting, will be cached. So logged-in users will have customized pages, but anonymous users will see a cached page. Since there are generally more anonymous users, using the AnonymousExpiresFilter can dramatically improve performance without losing the ability to customize pages.

Pages should call request.getSession(false) to get their sessions, because a page that creates a session will not be cached. For the same reason, JSP pages would set <jsp:directive.page session='false'/>.

The cache-time init-parameter configures how long the page should be cached:

 <filter>
   <filter-name>anonymous-cache</filter-name>
   <filter-class>com.caucho.http.filter.AnonymousExpiresFilter</filter-class>
   <init-param cache-time='10s'/>
 </filter>
 
The cache-time allows the standard extensions:
sseconds
mminutes
hhours
Ddays
Wweeks
Mmonths
Yyears

Since:
Resin 2.0.5

Constructor Summary
AnonymousExpiresFilter()
           
 
Method Summary
 void destroy()
          Any cleanup for the filter.
 void doFilter(ServletRequest request, ServletResponse response, FilterChain nextFilter)
          The filter add an Expires time in the future and adds the x-anonymous Cache-Control directive.
 void init(FilterConfig config)
          Filter init reads the filter configuration
 void setCacheTime(Period period)
          Sets the file cache time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnonymousExpiresFilter

public AnonymousExpiresFilter()
Method Detail

setCacheTime

public void setCacheTime(Period period)
Sets the file cache time.


init

public void init(FilterConfig config)
          throws ServletException
Filter init reads the filter configuration

Specified by:
init in interface Filter
Throws:
ServletException

doFilter

public void doFilter(ServletRequest request,
                     ServletResponse response,
                     FilterChain nextFilter)
              throws ServletException,
                     java.io.IOException
The filter add an Expires time in the future and adds the x-anonymous Cache-Control directive.

Specified by:
doFilter in interface Filter
Parameters:
request - the servlet request
response - the servlet response
nextFilter - the next filter in the chain
Throws:
ServletException
java.io.IOException

destroy

public void destroy()
Any cleanup for the filter.

Specified by:
destroy in interface Filter