|
Custom JSP tags. This taglib supports dynamic cache. You can cache a whole page or an any part (parts) of it. Also this taglib lets you simulate OutputCache directive in ASP.NET. Let us see this example:
<%@ taglib uri="taglib.tld" prefix="cache" %> <cache:Cache refresh="60" scope="session" key="abc"> <html> <% out.println(new java.util.Date()); %> </html> </cache:Cache> here calculation's results (HTML code) will be saved in the cache for 60 seconds. So for the each next request during that time client will get data directly from the cache (without the new evaluation for tag's body). Cached data may be persistent (this option should be described by the parameter store). Store is just some existing directory on your server. Saved cache could be restored (e.g. after crashes). Each data chunk must have own unique key. Under this key you may have more than one
cache each of them will be described by request's parameters and/or headers. For doing
this you can provide a list of parameters (semicolon separated) and/or a list of headers. E.g.:
<%@ taglib uri="taglib.tld" prefix="cache" %> <cache:Cache refresh="120" scope="application" varyByParam="user;qty" varyByHeader="user-agent" key="abc" store="c:\\tmp"> <!-- some code --> </cache:Cache> varyByParam parameter provides a semicolon-separated list of strings used to vary the output cache.
By default, these strings correspond to a query string value sent with GET method attributes, or a parameter sent
using the POST method. It is similar to an appropriate parameter in ASP.NET OutputCache directive.
When this attribute is set to multiple parameters, the output cache contains a different version of the requested body
for each specified parameter.
Note for ASP.NET users. To simulate VaryByCustom parameter you may use an expression in a key parameter. This expression could be for example a call to some function that calculates cache key by your own algorithm. Cache data are separated by the scope. You may cache data per sessions (actually it means caching per users) or per applications (actually it means caching for all users). Parameter refresh describes how long data will be saved in cache.
Another way to describe cache policy is to set some file name. In this case
cache validation depends on modification time for this file. Body will be re-evaluated
is last modification time has been changed. This option could be useful if
tag's body actually depends on this file (e.g. some xsl sheet etc.):
<cache:Cache depends="some_file.xsl" key="def"> <!-- some code --> </cache:Cache> Tag forEachKey lets you iterate over existing cache keys. E.g.:
<!-- list global caches --> <cache:forEachKey scope="application" id="currentKey"> Key is <%=currentKey%> </cache:forEachKey> Tags are: Cache This tag puts own body into cache or outputs cached data. Parameters are: 1) key data key (identification)
clearCache Clears cache for the given key (and all subcaches). Parameters are: 1) key data key (identification). You can omit this parameter
if you are using this tag inside of forEachKey tag.
getCache Prints cached data or puts them into page scope variable. If you set the parameter id data will be saved in the page scope variable described by this parameter. Otherwise tag just prints cached data. Parameters are: 1) key data key (identification). You can omit this parameter
if you are using this tag inside of forEachKey tag.
restoreCache Prints cached data from the given store or puts them into page scope variable. If you set the parameter id data will be saved in the page scope variable described by this parameter. Otherwise tag just prints cached data. Parameters are: 1) key data key (identification).
getHits Prints a counter for cache hits or saves it in the page scope variable. If you set the parameter id data will be saved in the page scope variable described by this parameter. Otherwise tag just prints data. Parameters are: 1) key data key (identification). You can omit this parameter
if you are using this tag inside of forEachKey tag.
getExecutions Prints a counter for cached data updates (body execution) or saves it in the page scope variable. If you set the parameter id data will be saved in the page scope variable described by this parameter. Otherwise tag just prints data. Parameters are: 1) key data key (identification). You can omit this parameter
if you are using this tag inside of forEachKey tag.
getLastModified Calculates a 'last modified' time for the given cache. If you set the parameter id data will be saved in the page scope variable described by this parameter (type is java.util.Date). Otherwise tag just prints data. Parameters are: 1) key data key (identification). You can omit this parameter
if you are using this tag inside of forEachKey tag.
ifCached Body tag. Executes own body in case of described cached data are detected. Parameters are: 1) key data key (identification)
ifNotCached Body tag. Executes own body in case of described cache does not exist. Parameters are: 1) key data key (identification)
forEachKey Body tag lets you iterate over existing cache keys. Tag executes own body for the each key in the given scope. Parameters are: 1) id Optional parameter. Describes a name for the page scope varible (type is
java.lang.String) you can use as a reference to the current key. Default value is cacheKey.
for downloading: Library: cachetag.jar Description: taglib.tld See also Coldtags suite - the largest collection of custom JSP tags.
|
Also in JSOS:
|