public class CSCache
extends BodyTagSupport
Read html from a "cache" file, alternatively write the file if it doesn't yet exist.
Note that the values of ArticleID, and StrVars will be used to generate a cachefile name, and must be safe to use in filenames
EXAMPLES:
Use caching on the results of some jsp code, this output depends only on "ArticleID" The cached version is considered current for 1/4 hour...
<%@ taglib uri="WEB-INF/cstags.tld" prefix="gi" %>
<gi:cache cachedir="D:\web\test\cache" preview="false" timeout="15" articleID="13" >
<%-- all the complicated workings that produce the page go here --%>
</gi:cache>
Use caching on the results of a block of code, this output does not depend on "ArticleID" but the variables "Level" and "Style" neither of which ever contain the '_' character. similar calls to the cache tag exist in other files. The cached version is considered current for 2 hours.
<gi:cache cachedir="D:\web\test\cache" templatefilepath="<%= page.getClass().getName()%>"
strVars="<%=Level + "_" + Style%>"
preview="false" timeout="120">
<%-- all the complicated workings that produce the page go here --%>
</gi:cache>
The setX
methods are called by the jsp engine to set the value of attribute X. If the attribute
preview
is set to "false" then setPreview("false");
will be called on the CSCache
object.
The DoStartTag
and DoEndTag
are called by jsp when the opening and closing tags are
encountered.
Constructor and Description |
---|
CSCache() |
Modifier and Type | Method and Description |
---|---|
int |
doEndTag()
Process closing custom tag.
|
int |
doStartTag()
Process opening custom tag.
|
void |
setArticleID(int id)
Set the article ID.
|
void |
setArticleID(java.lang.String id)
Set the article ID.
|
void |
setCachedir(java.lang.String s)
Set the directory to use for cache files.
|
void |
setCachesubdir(java.lang.String s)
Set the subdirectory within cachedir to use for cache files.
|
void |
setPreview(boolean p)
Set the state of the preview flag.
|
void |
setPreview(java.lang.String p)
Set the state of the preview flag.
|
void |
setStrVars(java.lang.String v)
Set the variable values which make this html output unique.
|
void |
setTemplatefilepath(java.lang.String t)
Set the name (and path) of the jsp file (or servlet) whose output is being cached.
|
void |
setTimeout(int t)
Set the maximum time that this cached content can be considered current.
|
void |
setTimeout(java.lang.String t)
Set the maximum time that this cached content can be considered current.
|
public void setCachedir(java.lang.String s)
s
- a String
containing the full path to the directory which will be used to hold cached
files.public void setCachesubdir(java.lang.String s)
s
- a String
containing the subdirectory which will be used to hold cached files.public void setTemplatefilepath(java.lang.String t)
t
- a String
containing the full path to the jsp file whose output is being cached, or a
similarly unique key.public void setStrVars(java.lang.String v)
For example, if a section of code produces a navigation menu for section S
, the value of S will
be provided in v and different cache files will be produced for S="home","documents","reference"...
The string used in v
must be safe to form part of a filename, and may need to include delimiting
characters to separate different component values.
v
- a String
containing the states of any variables which determine the output to cache.public void setArticleID(int id)
id
- an int
containing the article ID.public void setArticleID(java.lang.String id)
id
- a String
containing the article ID.public void setTimeout(int t)
t
- the number of minutes that this content will be re-used from cache rather than re-calculated.public void setTimeout(java.lang.String t)
t
- the number of minutes that this content will be re-used from cache rather than re-calculated.public void setPreview(boolean p)
p
- true
to disable caching.public void setPreview(java.lang.String p)
p
- true
to disable caching.public int doStartTag() throws JspException
JspException
- if a JSP error occurs whilst opening the tagpublic int doEndTag()
Copyright © 2022 Goss Interactive Ltd. All Rights Reserved.