|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.opensymphony.oscache.web.filter.CacheFilter
public class CacheFilter
CacheFilter is a filter that allows for server-side caching of post-processed servlet content.
It also gives great programatic control over refreshing, flushing and updating the cache.
Field Summary | |
---|---|
static long |
EXPIRES_OFF
|
static long |
EXPIRES_ON
|
static long |
EXPIRES_TIME
|
static int |
FRAGMENT_AUTODETECT
|
static int |
FRAGMENT_NO
|
static int |
FRAGMENT_YES
|
static String |
HEADER_ACCEPT_ENCODING
|
static String |
HEADER_CACHE_CONTROL
|
static String |
HEADER_CONTENT_ENCODING
|
static String |
HEADER_CONTENT_TYPE
|
static String |
HEADER_EXPIRES
|
static String |
HEADER_IF_MODIFIED_SINCE
|
static String |
HEADER_LAST_MODIFIED
|
static long |
LAST_MODIFIED_INITIAL
|
static long |
LAST_MODIFIED_OFF
|
static long |
LAST_MODIFIED_ON
|
static long |
MAX_AGE_NO_INIT
|
static long |
MAX_AGE_TIME
|
static int |
NOCACHE_OFF
|
static int |
NOCACHE_SESSION_ID_IN_URL
|
Constructor Summary | |
---|---|
CacheFilter()
|
Method Summary | |
---|---|
boolean |
acceptsGZipEncoding(HttpServletRequest request)
Check if the client browser support gzip compression. |
String[] |
createCacheGroups(HttpServletRequest httpRequest,
ServletCacheAdministrator scAdmin,
Cache cache)
ICacheGroupsProvider |
String |
createCacheKey(HttpServletRequest httpRequest,
ServletCacheAdministrator scAdmin,
Cache cache)
ICacheKeyProvider |
void |
destroy()
Filter clean-up |
void |
doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
The doFilter call caches the response by wrapping the HttpServletResponse
object so that the output stream can be caught. |
long |
getCacheControlMaxAge()
|
ICacheGroupsProvider |
getCacheGroupsProvider()
|
ICacheKeyProvider |
getCacheKeyProvider()
|
int |
getCacheScope()
Returns PageContext.APPLICATION_SCOPE or PageContext.SESSION_SCOPE. |
String |
getCron()
|
List |
getDisableCacheOnMethods()
|
long |
getExpires()
|
EntryRefreshPolicy |
getExpiresRefreshPolicy()
|
int |
getFragment()
|
long |
getLastModified()
|
int |
getNocache()
|
int |
getTime()
|
void |
init(FilterConfig filterConfig)
Initialize the filter. |
boolean |
isCacheable(CacheHttpServletResponseWrapper cacheResponse)
isCacheable is a method allowing subclass to decide if a response is cachable or not. |
boolean |
isCacheable(ServletRequest request)
isCacheable is a method allowing a subclass to decide if a request is cachable or not. |
boolean |
isFilteredBefore(ServletRequest request)
Checks if the request was filtered before, so guarantees to be executed once per request. |
boolean |
isFragment(HttpServletRequest request)
Checks if the request is a fragment in a page. |
void |
setCacheControlMaxAge(long cacheControlMaxAge)
max-age - defines the cache control response header max-age. |
void |
setCacheGroupsProvider(ICacheGroupsProvider cacheGroupsProvider)
ICacheGroupsProvider - Class implementing the interface ICacheGroupsProvider . |
void |
setCacheKeyProvider(ICacheKeyProvider cacheKeyProvider)
ICacheKeyProvider - Class implementing the interface ICacheKeyProvider . |
void |
setCacheScope(int cacheScope)
scope - the default scope to cache content. |
void |
setCron(String cron)
cron - defines an expression that determines when the page content will expire. |
void |
setDisableCacheOnMethods(List disableCacheOnMethods)
disableCacheOnMethods - Defines the http method name for which cacheing should be disabled. |
void |
setExpires(long expires)
expires - defines if the expires header will be sent in the response. |
void |
setExpiresRefreshPolicy(EntryRefreshPolicy expiresRefreshPolicy)
EntryRefreshPolicy - Class implementing the interface EntryRefreshPolicy . |
void |
setFragment(int fragment)
fragment - defines if this filter handles fragments of a page. |
void |
setLastModified(long lastModified)
lastModified - defines if the last modified header will be sent in the response. |
void |
setNocache(int nocache)
nocache - defines which objects shouldn't be cached. |
void |
setTime(int time)
time - the default time (in seconds) to cache content for. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String HEADER_LAST_MODIFIED
public static final String HEADER_CONTENT_TYPE
public static final String HEADER_CONTENT_ENCODING
public static final String HEADER_EXPIRES
public static final String HEADER_IF_MODIFIED_SINCE
public static final String HEADER_CACHE_CONTROL
public static final String HEADER_ACCEPT_ENCODING
public static final int FRAGMENT_AUTODETECT
public static final int FRAGMENT_NO
public static final int FRAGMENT_YES
public static final int NOCACHE_OFF
public static final int NOCACHE_SESSION_ID_IN_URL
public static final long LAST_MODIFIED_OFF
public static final long LAST_MODIFIED_ON
public static final long LAST_MODIFIED_INITIAL
public static final long EXPIRES_OFF
public static final long EXPIRES_ON
public static final long EXPIRES_TIME
public static final long MAX_AGE_NO_INIT
public static final long MAX_AGE_TIME
Constructor Detail |
---|
public CacheFilter()
Method Detail |
---|
public void destroy()
destroy
in interface Filter
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException
HttpServletResponse
object so that the output stream can be caught. This works by splitting off the output
stream into two with the SplitServletOutputStream
class. One stream gets written
out to the response as normal, the other is fed into a byte array inside a ResponseContent
object.
doFilter
in interface Filter
request
- The servlet requestresponse
- The servlet responsechain
- The filter chain
ServletException
- IOException
IOException
public void init(FilterConfig filterConfig)
ServletCacheAdministrator
instance and configures the filter based on any initialization parameters.The supported initialization parameters are:
init
in interface Filter
filterConfig
- The filter configurationpublic String createCacheKey(HttpServletRequest httpRequest, ServletCacheAdministrator scAdmin, Cache cache)
ICacheKeyProvider
createCacheKey
in interface ICacheKeyProvider
httpRequest
- the http request.scAdmin
- the ServletCacheAdministrator of the cachecache
- the cache of the ServletCacheAdministrator
ICacheKeyProvider.createCacheKey(javax.servlet.http.HttpServletRequest, ServletCacheAdministrator, Cache)
public String[] createCacheGroups(HttpServletRequest httpRequest, ServletCacheAdministrator scAdmin, Cache cache)
ICacheGroupsProvider
createCacheGroups
in interface ICacheGroupsProvider
httpRequest
- the http request.scAdmin
- the ServletCacheAdministrator of the cachecache
- the cache of the ServletCacheAdministrator
ICacheGroupsProvider.createCacheGroups(javax.servlet.http.HttpServletRequest, ServletCacheAdministrator, Cache)
public boolean isFragment(HttpServletRequest request)
javax.servlet.include.request_uri
is set.
According to Java Servlet API 2.3 this is excepted for servlets obtained
by using the getNamedDispatcher method.
request
- the to be handled request
public boolean isFilteredBefore(ServletRequest request)
request
- checks if the request was filtered before.
public boolean isCacheable(ServletRequest request)
request
- The servlet request
public boolean isCacheable(CacheHttpServletResponseWrapper cacheResponse)
cacheResponse
- the HTTP servlet response
public boolean acceptsGZipEncoding(HttpServletRequest request)
request
- the http request
public long getCacheControlMaxAge()
public void setCacheControlMaxAge(long cacheControlMaxAge)
MAX_AGE_NO_INIT
for don't initializing the max-age cache control,
MAX_AGE_TIME
the max-age information will be based on the time parameter and creation time of the content (expiration timestamp minus current timestamp), and
[positive integer]
value constant in seconds to be set in every response, the default value is 60.
cacheControlMaxAge
- the cacheControlMaxAge to setpublic ICacheGroupsProvider getCacheGroupsProvider()
public void setCacheGroupsProvider(ICacheGroupsProvider cacheGroupsProvider)
ICacheGroupsProvider
.
A developer can implement a method which provides cache groups based on the request,
the servlect cache administrator and cache. The parameter has to be not null
.
cacheGroupsProvider
- the cacheGroupsProvider to setpublic ICacheKeyProvider getCacheKeyProvider()
public void setCacheKeyProvider(ICacheKeyProvider cacheKeyProvider)
ICacheKeyProvider
.
A developer can implement a method which provides cache keys based on the request,
the servlect cache administrator and cache. The parameter has to be not null
.
cacheKeyProvider
- the cacheKeyProvider to setpublic int getCacheScope()
public void setCacheScope(int cacheScope)
PageContext.APPLICATION_SCOPE
(default) and PageContext.SESSION_SCOPE
.
cacheScope
- the cacheScope to setpublic String getCron()
public void setCron(String cron)
cron
- the cron to setpublic long getExpires()
public void setExpires(long expires)
EXPIRES_OFF
for don't sending the header, even it is set in the filter chain,
EXPIRES_ON
(default) for sending it if it is set in the filter chain and
EXPIRES_TIME
the expires information will be intialized based on the time parameter and creation time of the content.
expires
- the expires to setpublic EntryRefreshPolicy getExpiresRefreshPolicy()
public void setExpiresRefreshPolicy(EntryRefreshPolicy expiresRefreshPolicy)
EntryRefreshPolicy
.
A developer can implement a class which provides a different custom cache invalidation policy for a specific cache entry.
If not specified, the default policy is timed entry expiry as specified with the time parameter described above.
expiresRefreshPolicy
- the expiresRefreshPolicy to setpublic int getFragment()
public void setFragment(int fragment)
FRAGMENT_AUTODETECT
(default) for auto detect, FRAGMENT_NO
and FRAGMENT_YES
.
fragment
- the fragment to setpublic long getLastModified()
public void setLastModified(long lastModified)
LAST_MODIFIED_OFF
for don't sending the header, even it is set in the filter chain,
LAST_MODIFIED_ON
for sending it if it is set in the filter chain and
LAST_MODIFIED_INITIAL
(default) the last modified information will be set based on the current time and changes are allowed.
lastModified
- the lastModified to setpublic int getNocache()
public void setNocache(int nocache)
NOCACHE_OFF
(default) and NOCACHE_SESSION_ID_IN_URL
if the session id is
contained in the URL.
nocache
- the nocache to setpublic int getTime()
public void setTime(int time)
time
- the time to setpublic List getDisableCacheOnMethods()
public void setDisableCacheOnMethods(List disableCacheOnMethods)
null
for cacheing all requests without regarding the method name.
disableCacheOnMethods
- the list of http method names for which cacheing should be disabled
|
OSCache Project Page | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |