|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.servlet.jsp.tagext.TagSupport
javax.servlet.jsp.tagext.BodyTagSupport
com.opensymphony.oscache.web.tag.CacheTag
public class CacheTag
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>
Field Summary | |
---|---|
private String |
actualKey
The actual key to use. |
private ServletCacheAdministrator |
admin
|
private Cache |
cache
|
private static String |
CACHE_TAG_COUNTER_KEY
The key under which the tag counter will be stored in the request |
(package private) boolean |
cancelUpdateRequired
A flag to indicate whether a NeedsRefreshException was thrown and the update needs to be cancelled |
private String |
content
The content that was retrieved from cache |
private String |
cron
The cron expression that is used to expire cache entries at specific dates and/or times. |
private static int |
DAY
|
private static int |
DEFAULT_TIMEOUT
|
private List |
groups
If no groups are specified, the cached content does not get put into any groups |
private static int |
HOUR
|
private String |
key
if cache key is null, the request URI is used |
private String |
language
The ISO-639 language code to distinguish different pages in application scope |
private static org.apache.commons.logging.Log |
log
|
private static int |
MINUTE
|
private int |
mode
The cache mode. |
private static int |
MONTH
|
private static int |
ONE_HOUR
|
private static int |
ONE_MINUTE
Constants for refresh time |
private boolean |
refresh
Whether the cache should be refreshed instantly |
private String |
refreshPolicyClass
Class used to handle the refresh policy logic |
private String |
refreshPolicyParam
Parameters that will be passed to the init method of the refresh policy instance. |
private int |
scope
The cache scope to use |
private static int |
SECOND
Constants for time computation |
private static int |
SILENT_MODE
Cache modes |
private int |
time
time (in seconds) before cache should be refreshed |
private boolean |
useBody
used for subtags to tell this tag that we should use the cached version |
private static int |
WEEK
|
private static int |
YEAR
|
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 | |
---|---|
(package private) void |
addGroup(String group)
Adds to the groups for this cache entry. |
(package private) void |
addGroups(String groupsString)
Adds comma-delimited list of groups that the cache entry belongs to. |
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. |
private int |
parseDuration(String duration)
Convert a SimpleDateFormat string to seconds Acceptable format are : 0s (seconds) 0m (minute) 0h (hour) 0d (day) 0w (week) |
private int |
parseISO_8601_Duration(String duration)
Parse an ISO-8601 format date and return it's value in seconds |
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. |
private void |
validateDateFormat(String basicDate)
Validate the basic date format |
private void |
validateHourFormat(String basicHour)
Validate the basic hour format |
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 |
Field Detail |
---|
private static final int SECOND
private static final int MINUTE
private static final int HOUR
private static final int DAY
private static final int WEEK
private static final int MONTH
private static final int YEAR
private static final String CACHE_TAG_COUNTER_KEY
private static final int ONE_MINUTE
private static final int ONE_HOUR
private static final int DEFAULT_TIMEOUT
private static transient org.apache.commons.logging.Log log
private static final int SILENT_MODE
boolean cancelUpdateRequired
private Cache cache
private List groups
private ServletCacheAdministrator admin
private String actualKey
private String content
private String cron
private String key
private String language
private String refreshPolicyClass
private String refreshPolicyParam
private boolean refresh
private boolean useBody
private int mode
private int scope
private int time
Constructor Detail |
---|
public CacheTag()
Method Detail |
---|
public void setDuration(String duration)
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).public void setCron(String cron)
public void setGroups(String groups)
groups
- A comma-delimited list of groups that the cache entry belongs to.void addGroup(String group)
group
- A group to which the cache entry should belong.void addGroups(String groupsString)
groups
- A comma-delimited list of groups that the cache entry belongs to also.public void setKey(String key)
key
- The key for this cache entry.public void setLanguage(String language)
language
- The language code for this cache entry.public void setRefresh(boolean refresh)
refresh
- Whether or not to refresh this cache entry immediately.public void setMode(String mode)
true
prevents the cache from writing any output
to the response, however the JSP content is still cached as normal.
mode
- The cache mode to use.public void setRefreshpolicyclass(String refreshPolicyClass)
public void setRefreshpolicyparam(String refreshPolicyParam)
public void setScope(String scope)
scope
- The scope of this cache. Either "application" (default) or "session".public void setTime(int time)
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)public void setUseBody(boolean useBody)
It is most often called by the <UseCached /> tag to tell this tag to use the cached content.
useBody
- Whether or not to use the cached content.UseCachedTag
public int doAfterBody() throws javax.servlet.jsp.JspTagException
doAfterBody
in interface javax.servlet.jsp.tagext.IterationTag
doAfterBody
in class javax.servlet.jsp.tagext.BodyTagSupport
javax.servlet.jsp.JspTagException
- The standard exception thrown.public void doCatch(Throwable throwable) throws Throwable
doCatch
in interface javax.servlet.jsp.tagext.TryCatchFinally
Throwable
public int doEndTag() throws javax.servlet.jsp.JspTagException
doEndTag
in interface javax.servlet.jsp.tagext.Tag
doEndTag
in class javax.servlet.jsp.tagext.BodyTagSupport
javax.servlet.jsp.JspTagException
- The standard exception thrown.public void doFinally()
doFinally
in interface javax.servlet.jsp.tagext.TryCatchFinally
public int doStartTag() throws javax.servlet.jsp.JspTagException
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.
doStartTag
in interface javax.servlet.jsp.tagext.Tag
doStartTag
in class javax.servlet.jsp.tagext.BodyTagSupport
javax.servlet.jsp.JspTagException
- The standard exception thrown.private int parseDuration(String duration)
duration
- The simple date time to parse
private int parseISO_8601_Duration(String duration) throws Exception
duration
- The ISO-8601 date
Exception
private void validateDateFormat(String basicDate) throws Exception
basicDate
- The string to validate
Exception
private void validateHourFormat(String basicHour) throws Exception
basicHour
- The string to validate
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |