com.opensymphony.oscache.web.tag
public class: FlushTag [javadoc |
source]
java.lang.Object
javax.servlet.jsp.tagext.TagSupport
com.opensymphony.oscache.web.tag.FlushTag
All Implemented Interfaces:
IterationTag, Serializable
FlushTag flushes caches created with <cache>.
This tag provides programmatic control over when caches are flushed,
and can flush all caches at once.
Usage Examples:
<%@ taglib uri="oscache" prefix="cache" %>
<cache:flush scope="application" />
<cache:flush scope="session" key="foobar" />
Note: If no scope is provided (or scope is null), it will flush
all caches globally - use with care!
Flushing is done by setting an appropriate application level time,
which <cache> always looks at before retrieving the cache.
If this 'flush time' is > that cache's last update, it will refresh
the cache.
As such caches are not all 'flushed', they are all marked
to be refreshed at their next access. That is the only way that
the content can still be available if the refresh fails.
- author:
< - a href="mailto:mike@atlassian.com">Mike Cannon-Brookes
- author:
< - a href="mailto:chris@swebtec.com">Chris Miller
- version:
$ - Revision: 254 $
| Field Summary |
|---|
| ServletCacheAdministrator | admin | |
| String | group | A cache group.
If specified, all content in that group will be flushed |
| String | key | Tag key. |
| String | pattern | if pattern value is specified, all keys that contain the pattern are flushed. |
| String | scope | |
| int | cacheScope | |
| Methods from javax.servlet.jsp.tagext.TagSupport: |
|---|
|
doAfterBody, doEndTag, doStartTag, findAncestorWithClass, getId, getParent, getValue, getValues, release, removeValue, setId, setPageContext, setParent, setValue |
| Method from com.opensymphony.oscache.web.tag.FlushTag Detail: |
public int doStartTag() throws JspTagException {
if (admin == null) {
admin = ServletCacheAdministrator.getInstance(pageContext.getServletContext());
}
if (group != null) // We're flushing a group
{
if (cacheScope >= 0) {
Cache cache = admin.getCache((HttpServletRequest) pageContext.getRequest(), cacheScope);
cache.flushGroup(group);
} else {
throw new JspTagException("A cache group was specified for flushing, but the scope wasn't supplied or was invalid");
}
} else if (pattern != null) // We're flushing keys which contain the pattern
{
if (cacheScope >= 0) {
Cache cache = admin.getCache((HttpServletRequest) pageContext.getRequest(), cacheScope);
cache.flushPattern(pattern);
} else {
throw new JspTagException("A pattern was specified for flushing, but the scope wasn't supplied or was invalid");
}
} else if (key == null) // we're flushing a whole scope
{
if (cacheScope >= 0) {
admin.setFlushTime(cacheScope);
} else {
admin.flushAll();
}
} else // we're flushing just one key
{
if (cacheScope >= 0) {
String actualKey = admin.generateEntryKey(key, (HttpServletRequest) pageContext.getRequest(), cacheScope, language);
Cache cache = admin.getCache((HttpServletRequest) pageContext.getRequest(), cacheScope);
cache.flushEntry(actualKey);
} else {
throw new JspTagException("A cache key was specified for flushing, but the scope wasn't supplied or was invalid");
}
}
return SKIP_BODY;
}
Process the start of the tag. |
public void setGroup(String group) {
this.group = group;
}
The group to be flushed.
If specified, all cached content in the group will be flushed. |
public void setKey(String value) {
this.key = value;
}
The key to be flushed.
If specified, only one cache entry will be flushed. |
public void setLanguage(String value) {
this.language = value;
}
Set the ISO-639 language code to distinguish different pages in application scope. |
public void setPattern(String value) {
this.pattern = value;
}
The key pattern to be flushed.
If specified, all entries that contain the pattern will be flushed. |
public void setScope(String value) {
if (value != null) {
if (value.equalsIgnoreCase(ServletCacheAdministrator.SESSION_SCOPE_NAME)) {
cacheScope = PageContext.SESSION_SCOPE;
} else if (value.equalsIgnoreCase(ServletCacheAdministrator.APPLICATION_SCOPE_NAME)) {
cacheScope = PageContext.APPLICATION_SCOPE;
}
}
}
Set the scope of this flush. |