Caching servlets and JSPs

The process of caching servlets and JSPs is explained and illustrated.

When the application server starts and a targeted servlet or JSP is called for the first time, no cached entry is found and so the service() method of the servlet is called. The DynaCache Web container intercepts the response from the service() invocation and caches the results. This process is illustrated in Figure 1.

Figure 1. Before caching: A request must traverse all layers
This figure is an overview of what is required before caching. A request must traverse all layers.

The next time that the servlet is called and a match is found in the caching rules engine, the cached results are returned and the service() method is not called. This bypasses all of the processing that would have been done by the servlet, resulting in a substantial performance boost.

If, however, there is no cache entry for this ID, the service() method is run as normal, and the results are caught and placed in the cache before they are returned to the requester.

Figure 2 illustrates how DynaCache increases performance by bypassing the service() method call entirely whenever a cache hit occurs.

Figure 2. A cache hit means that the servlet and business logic is not called
This figure illustrates that a cache hit means that the servlet and business logic is not called.

Servlets and JSPs are configured for caching with entries in the file cachespec.xml.