How do we implement caching in JSP?

How do we implement caching in JSP?

JSP caching lets you cache tag invocation results within the Java engine. Each can be cached using different cache criteria. JSP caching is defined by following:

1. Enabling JSP caching: To globally enable JSP caching, set the jspCachingEnabled property to true. The default is false. For Example

asadmin set server-config.web-container.property.jspCachingEnabled="true"
To enable JSP caching for a single web application, follow these steps:

-Extract the META-INF/appserv-tags.tld file from the as-install/glassfish/modules/web-glue.jar file.
-Create a new JAR file (for example, appserv-tags.jar) containing just the META-INF/appserv-tags.tld file previously extracted.
-Bundle this new JAR file in the WEB-INF/lib directory of your web application.

2. Caching Scope: JSP caching is available in three different scopes: request, session, and application. The default is application. To use a cache in request scope, a web application must specify the com.sun.appserv.web.taglibs.cache.CacheRequestListener in its web.xml deployment descriptor, as follows:

<listener>
   <listener-class>
com.sun.appserv.web.taglibs.cache.CacheRequestListener
   <listener-class>
<listener>


3. Cache Tag: The cache tag caches the body between the beginning and ending tags according to the attributes specified. The first time the tag is encountered; the body content is executed and cached. Each subsequent time it is run, the cached content is checked to see if it needs to be refreshed and if so, it is executed again, and the cached data is refreshed. Otherwise, the cached data is served.

4. Flush tag: Forces the cache to be flushed. If a key is specified, only the entry with that key is flushed. If no key is specified, the entire cache is flushed.
Different Authentication options in Servlets
Authentication options available in Servlets: There are four different options for authentication in servlets...
How can we use beans in JSP?
Java Beans are reusable components. They are used to separate Business Logic from Presentation Logic. Internally a bean is just an instance of a class...
Difference between JavaBeans and taglib directives
A Java Bean is a reusable software component that can be visually manipulated in builder tools. They can’t manipulate JSP content...
Post your comment