public class AnonymousExpiresFilter extends java.lang.Object implements Filter
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:
s | seconds |
m | minutes |
h | hours |
D | days |
W | weeks |
M | months |
Y | years |
Constructor and Description |
---|
AnonymousExpiresFilter() |
Modifier and Type | Method and Description |
---|---|
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.
|
public void setCacheTime(Period period)
public void init(FilterConfig config) throws ServletException
init
in interface Filter
ServletException
public void doFilter(ServletRequest request, ServletResponse response, FilterChain nextFilter) throws ServletException, java.io.IOException
doFilter
in interface Filter
request
- the servlet requestresponse
- the servlet responsenextFilter
- the next filter in the chainServletException
java.io.IOException