com.opensymphony.oscache.web.tag
Class CacheTag

java.lang.Object
  extended by javax.servlet.jsp.tagext.TagSupport
      extended by javax.servlet.jsp.tagext.BodyTagSupport
          extended by com.opensymphony.oscache.web.tag.CacheTag
All Implemented Interfaces:
Serializable, BodyTag, IterationTag, Tag, TryCatchFinally

public class CacheTag
extends BodyTagSupport
implements TryCatchFinally

CacheTag is a tag that allows for server-side caching of post-processed JSP content.

It also gives great programatic control over refreshing, flushing and updating the cache.

Usage Example:


     <%@ taglib uri="oscache" prefix="cache" %>
     <cache:cache key="mycache"
                 scope="application"
                 refresh="false"
                 time="30">
              jsp content here... refreshed every 30 seconds
     </cache:cache>
 

Version:
$Revision: 331 $
Author:
Mike Cannon-Brookes, Todd Gochenour, Francois Beauregard, Alain Bergevin
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.servlet.jsp.tagext.BodyTagSupport
bodyContent
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContext
 
Fields inherited from interface javax.servlet.jsp.tagext.BodyTag
EVAL_BODY_BUFFERED, EVAL_BODY_TAG
 
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
CacheTag()
           
 
Method Summary
 int doAfterBody()
          After the cache body, either update the cache, serve new cached content or indicate an error.
 void doCatch(Throwable throwable)
           
 int doEndTag()
          The end tag - clean up variables used.
 void doFinally()
           
 int doStartTag()
          The start of the tag.
 void setCron(String cron)
          Sets the cron expression that should be used to expire content at specific dates and/or times.
 void setDuration(String duration)
          Set the time this cache entry will be cached for.
 void setGroups(String groups)
          Sets the groups for this cache entry.
 void setKey(String key)
          Set the key for this cache entry.
 void setLanguage(String language)
          Set the ISO-639 language code to distinguish different pages in application scope
 void setMode(String mode)
          Setting this to true prevents the cache from writing any output to the response, however the JSP content is still cached as normal.
 void setRefresh(boolean refresh)
          This method allows the user to programatically decide whether the cached content should be refreshed immediately.
 void setRefreshpolicyclass(String refreshPolicyClass)
          Class used to handle the refresh policy logic
 void setRefreshpolicyparam(String refreshPolicyParam)
          Parameters that will be passed to the init method of the refresh policy instance.
 void setScope(String scope)
          Set the scope of this cache.
 void setTime(int time)
          Set the time this cache entry will be cached for (in seconds)
 void setUseBody(boolean useBody)
          This controls whether or not the body of the tag is evaluated or used.
 
Methods inherited from class javax.servlet.jsp.tagext.BodyTagSupport
doInitBody, getBodyContent, getPreviousOut, release, setBodyContent
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.jsp.tagext.Tag
getParent, setPageContext, setParent
 

Constructor Detail

CacheTag

public CacheTag()
Method Detail

setDuration

public void setDuration(String duration)
Set the time this cache entry will be cached for. A date and/or time in either ISO-8601 format or a simple format can be specified. The acceptable syntax for the simple format can be any one of the following:

Parameters:
duration - The duration to cache this content (using either the simple or the ISO-8601 format). Passing in a duration of zero will turn off the caching, while a negative value will result in the cached content never expiring (ie, the cached content will always be served as long as it is present).

setCron

public void setCron(String cron)
Sets the cron expression that should be used to expire content at specific dates and/or times.


setGroups

public void setGroups(String groups)
Sets the groups for this cache entry. Any existing groups will be replaced.

Parameters:
groups - A comma-delimited list of groups that the cache entry belongs to.

setKey

public void setKey(String key)
Set the key for this cache entry.

Parameters:
key - The key for this cache entry.

setLanguage

public void setLanguage(String language)
Set the ISO-639 language code to distinguish different pages in application scope

Parameters:
language - The language code for this cache entry.

setRefresh

public void setRefresh(boolean refresh)
This method allows the user to programatically decide whether the cached content should be refreshed immediately.

Parameters:
refresh - Whether or not to refresh this cache entry immediately.

setMode

public void setMode(String mode)
Setting this to true prevents the cache from writing any output to the response, however the JSP content is still cached as normal.

Parameters:
mode - The cache mode to use.

setRefreshpolicyclass

public void setRefreshpolicyclass(String refreshPolicyClass)
Class used to handle the refresh policy logic


setRefreshpolicyparam

public void setRefreshpolicyparam(String refreshPolicyParam)
Parameters that will be passed to the init method of the refresh policy instance.


setScope

public void setScope(String scope)
Set the scope of this cache.

Parameters:
scope - The scope of this cache. Either "application" (default) or "session".

setTime

public void setTime(int time)
Set the time this cache entry will be cached for (in seconds)

Parameters:
time - The time to cache this content (in seconds). Passing in a time of zero will turn off the caching. A negative value for the time will result in the cached content never expiring (ie, the cached content will always be served if it is present)

setUseBody

public void setUseBody(boolean useBody)
This controls whether or not the body of the tag is evaluated or used.

It is most often called by the <UseCached /> tag to tell this tag to use the cached content.

Parameters:
useBody - Whether or not to use the cached content.
See Also:
UseCachedTag

doAfterBody

public int doAfterBody()
                throws JspTagException
After the cache body, either update the cache, serve new cached content or indicate an error.

Specified by:
doAfterBody in interface IterationTag
Overrides:
doAfterBody in class BodyTagSupport
Returns:
The standard BodyTag return.
Throws:
JspTagException - The standard exception thrown.

doCatch

public void doCatch(Throwable throwable)
             throws Throwable
Specified by:
doCatch in interface TryCatchFinally
Throws:
Throwable

doEndTag

public int doEndTag()
             throws JspTagException
The end tag - clean up variables used.

Specified by:
doEndTag in interface Tag
Overrides:
doEndTag in class BodyTagSupport
Returns:
The standard BodyTag return.
Throws:
JspTagException - The standard exception thrown.

doFinally

public void doFinally()
Specified by:
doFinally in interface TryCatchFinally

doStartTag

public int doStartTag()
               throws JspTagException
The start of the tag.

Grabs the administrator, the cache, the specific cache entry, then decides whether to refresh.

If no refresh is needed, this serves the cached content directly.

Specified by:
doStartTag in interface Tag
Overrides:
doStartTag in class BodyTagSupport
Returns:
The standard doStartTag() return.
Throws:
JspTagException - The standard exception thrown.

OSCache Project Page