org.hd.d.pg2k.webSvr.util
Class ExplicitCacheTimeFilter

java.lang.Object
  extended by org.hd.d.pg2k.webSvr.util.ExplicitCacheTimeFilter
All Implemented Interfaces:
javax.servlet.Filter

public final class ExplicitCacheTimeFilter
extends java.lang.Object
implements javax.servlet.Filter

Explicitly allows browser to cache filtered items. This sets values that explicitly allow the client to cache the item for a longish time (of the order of hours to weeks) on the assumption that the filtered item changes slowly.

This should work even when the items are delivered over HTTPS, which would normally prevent them being cached.

This should work for HTTP/1.0 clients (we set Expires), and HTTP/1.1 client (we set Cache-Control).

This filter is stateless and as lightweight and simple as possible.


Field Summary
private static java.lang.String ANTI_DUP_ATTR_NAME
          Name of attribute that we use to avoid duplicate application of this filter on one filter chain.
private static java.lang.String[] DANGER_HEADERS
          Headers that we set to make cacheing work.
 
Constructor Summary
ExplicitCacheTimeFilter()
           
 
Method Summary
 void destroy()
          Take this filter out of service.
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
          Filter one item.
 void init(javax.servlet.FilterConfig filterConfig)
          Bring filter into service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DANGER_HEADERS

private static final java.lang.String[] DANGER_HEADERS
Headers that we set to make cacheing work. We reject attempts to override any of these (and warn on System.err).

These should be matched case-insensitively.


ANTI_DUP_ATTR_NAME

private static final java.lang.String ANTI_DUP_ATTR_NAME
Name of attribute that we use to avoid duplicate application of this filter on one filter chain.

See Also:
Constant Field Values
Constructor Detail

ExplicitCacheTimeFilter

public ExplicitCacheTimeFilter()
Method Detail

init

public void init(javax.servlet.FilterConfig filterConfig)
Bring filter into service.

Specified by:
init in interface javax.servlet.Filter

destroy

public void destroy()
Take this filter out of service.

Specified by:
destroy in interface javax.servlet.Filter

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws java.io.IOException,
                     javax.servlet.ServletException
Filter one item. If none of the cache-controlling headers for HTTP/1.0 or 1.1 are already set, set them ourselves to a reasonably lengthy time.

Specified by:
doFilter in interface javax.servlet.Filter
Throws:
java.io.IOException
javax.servlet.ServletException

DHD Multimedia Gallery V1.57.21

Copyright (c) 1996-2011, Damon Hart-Davis. All rights reserved.