LRU cache taglib ver. 1.2


    Custom JSP taglib. Lets you cache information in memory. How does it work? The main tag is Cache. This taglib requests data fron cache (by the key). In case of success tag prints (outputs) cached data. Otherwise tag evaluates own body, prints it and saves in the cache. So for the next request it could be obtained from the cache. If cache does not exist it will be created here. Here is an idea:
 


<html>
<%@ taglib uri="taglib.tld" prefix="c" %>

<c:Cache id="A" scope="application" key="k1">
<%=new java.util.Date()%>
</c:Cache>
</html>

You will get the once calculated time in the subsequential requests. Tag getCache lets you simply request data from cache (without putting them in). Also you can directly remove data from cache.

You can cache data on the global (application) level or per user (session scope). Also in your application you can have more than one cache, each of them will be described by the own unique id.

Each cache has got a limited size (50 records) and supports LRU (Least Recently Used) filling scheme. So the old records will be automatically replaced with the newest on case of overloading.

Tags are:

Cache.

Body tag caches data or gets them from LRU cache. Attributes are:

1) id - describes an unique id for your cache
2) scope - Optional attribute. Describes a scope for your cache. Possible values are application or session. Default value is session.
3) key - describes a key for data

getCache.

Body tag requests data from cache. Tag prints data or saves them in the page scope variable (type is java.lang.String). Otherwise (no cache or data in cache) tag's body will be executed. Attributes are:

1) id - describes an unique id for your cache
2) scope - Optional attribute. Describes a scope for your cache. Possible values are application or session. Default value is session.
3) key - describes a key for data
4) res - Optional attribute. Describes a name for your page scope variable (type is java.lang.String). Without this parameter tag simply prints data.

remove.

Tag removes data from cache. Attributes are:

1) id - describes an unique id for your cache
2) scope - Optional attribute. Describes a scope for your cache. Possible values are application or session. Default value is session.
3) key - describes a key for data
4) cond - Optional attribute. Describes a boolean value tag's behavior depends on. Default value is true (remove)

clear.

Tag removes all data from cache. Attributes are:

1) id - describes an unique id for your cache
2) scope - Optional attribute. Describes a scope for your cache. Possible values are application or session. Default value is session.
3) cond - Optional attribute. Describes a boolean value tag's behavior depends on. Default value is true (clear cache)

for downloading:

Library: lrucachetag.jar     Description: taglib.tld

 © Coldbeans      Comments?

See also Coldtags suite - the largest collection of custom JSP tags.

Also in Coldtags: