Overview | Package | Class | Tree | Deprecated | Index | Help
| J2EE1.4 SDK
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.sun.appserv.web.taglibs.cache
Class CacheTag

    java.lang.Object
      javax.servlet.jsp.tagext.TagSupport
          javax.servlet.jsp.tagext.BodyTagSupport
              com.sun.appserv.web.taglibs.cache.CacheTag

All Implemented Interfaces:
  BodyTag, IterationTag, JspTag, java.io.Serializable, Tag

public class CacheTag
extends BodyTagSupport

CacheTag is a JSP tag that allows server-side caching of JSP page fragments. It lets you specify a timeout for how long the cached data is valid. It also gives you programmatic control over key generation, refreshing of the cache and whether the cached content should be served or not. Usage Example: <%@ taglib prefix="ias" uri="Sun ONE Application Server Tags" %> ... expensive operation ...

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()` Default constructor that simply gets a handle to the web container subsystem's logger.

Method Summary
`int` | `doAfterBody()` doAfterBody is called only if the body was evaluated.
`int` | `doEndTag()` doEndTag just resets all the valiables in case the tag is reused
`int` | `doStartTag()` doStartTag is called every time the cache tag is encountered.
`void` | `setKey(java.lang.String key)` This is used to set a user-defined key to store the response in the cache.
`void` | `setNocache(boolean noCache)` This attribute is used to programmatically enable or disable the use of the cached response.
`void` | `setRefresh(boolean refresh)` This attribute is used to programmatically refresh the cached response.
`void` | `setScope(java.lang.String scope)` This attribute is used to set the scope of the cache.
`void` | `setTimeout(java.lang.String timeout)` This sets the time for which the cached response is valid.

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()

  Default constructor that simply gets a handle to the web container subsystem's logger.

Method Detail

### doStartTag

    public int doStartTag()
                   throws JspException

  doStartTag is called every time the cache tag is encountered. By the time this is called, the tag attributes are already set, but the tag body has not been evaluated. The cache key is generated here and the cache is obtained as well

  Specified by:
    `doStartTag` in interface `Tag`
  Overrides:
    `doStartTag` in class `BodyTagSupport`
  Returns:
    EVAL_BODY_INCLUDE when nocache is specified so that the tag body is just evaluated into the output stream SKIP_BODY if the cached response is valid in which case it is just written to the output stream, hence there is nothing more to be done. EVAL_BODY_BUFFERED is the default return value which ensures that the BodyContent is created and the tag body is evaluated into it.
  Throws:
    `JspException` - the standard exception thrown
  See Also:
    `Tag.doStartTag()`

### doAfterBody

    public int doAfterBody()
                    throws JspException

  doAfterBody is called only if the body was evaluated. This would happen if nocache is specified in which case this should do nothing if there was no cached response in which case the response data is obtained from the bodyContent and cached if the response has expired in which case the cache is refreshed

  Specified by:
    `doAfterBody` in interface `IterationTag`
  Overrides:
    `doAfterBody` in class `BodyTagSupport`
  Returns:
    always returns SKIP_BODY since we dont do any iteration
  Throws:
    `JspException` - the standard exception thrown
  See Also:
    `BodyTagSupport.doInitBody()`, `IterationTag.doAfterBody()`

### doEndTag

    public int doEndTag()
                 throws JspException

  doEndTag just resets all the valiables in case the tag is reused

  Specified by:
    `doEndTag` in interface `Tag`
  Overrides:
    `doEndTag` in class `BodyTagSupport`
  Returns:
    always returns EVAL_PAGE since we want the entire jsp evaluated
  Throws:
    `JspException` - the standard exception thrown
  See Also:
    `Tag.doEndTag()`

### setKey

    public void setKey(java.lang.String key)

  This is used to set a user-defined key to store the response in the cache.

### setTimeout

    public void setTimeout(java.lang.String timeout)

  This sets the time for which the cached response is valid. The cached entry is invalid after this time is past. If no unit is specified, then the timeout is assumed to be in seconds. A different unit can be specified by postfixing the timeout value with the desired unit: s=seconds, m=minutes, h=hours, d=days

### setNocache

    public void setNocache(boolean noCache)

  This attribute is used to programmatically enable or disable the use of the cached response. If noCache is true, then the cached response is not sent, instead the tag body is evaluated and sent out, the cache is not refreshed either.

### setRefresh

    public void setRefresh(boolean refresh)

  This attribute is used to programmatically refresh the cached response. If refresh is true, the cached response is not sent, instead the tag body is evaluated and sent and the cache is refreshed with the new response.

### setScope

    public void setScope(java.lang.String scope)

  This attribute is used to set the scope of the cache. It can be either "session" or "application".

Overview | Package | Class | Tree | Deprecated | Index | Help
| J2EE1.4 SDK
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Submit a bug or feature

Copyright 2003 Sun Microsystems, Inc. All rights reserved.