To enhance the performance of a web site, software engineers usually perform code optimization and cache control. Code optimization involves removing unnecessary data, streamlining business logic and source code. Cache control involves storing commonly accessed instructions in fast accessed medium such as RAM.
Usually code optimization and cache control is a manual process for the developer to perform before deployment. This is a tedious and time-consuming process where the developer and tester are required to locate the slow pages, scan through the code to streamline the business logic and the source code, and cut down unnecessary code and logic. Then the engineer needs to identify frequently accessed objects and develops caching solutions for them.
This article describes MadCaching, a dynamic server-side cache control solution for Struts and Tiles programmers. With Struts and Tiles, web caching can be turned off and on with a few configuration steps, however code optimization continues to remain a manual process.
Struts is a Controller framework based on the Model-View-Controller design pattern (Figure 1). The Controller accepts incoming requests and forwards them to the appropriate handler. The handler then calls the appropriate Model. The Model is responsible for the business logic and state. The handler sends the forwarded information back to the controller to display the View. The View sends the HTML page back to the response. Refer to http://struts.apache.org for more information on Struts.
Tiles framework allows templating and componentization of the View. Templating separates HTML page into several different portions called tiles. Figure 2 illustrates a HTML page separate into tiles: header, menu, body, and footer.
Componentization allows the tiles to be reused in other templates. Refer to http://struts.apache.org/userGuide/dev_tiles.html for more information about Tiles. The Tile Resources section of this web page is a good start.
MadCaching is an extension of Tile framework. It provides the ability to enable or disable caching for a tile on demand. A designer or coder does not have to worry about caching during implementation. He/she can program tiles as normal. On deployment, with a few configuration changes to the web.xml and struts-config.xml file, he/she can take advantage the build-in caching module.
In effect, MadCaching eliminates the need for the designer or coder to implement a customized cache control. The use cases corresponding to MadCaching is illustrated in Figure 3. The User involvement in MadCaching is transparent. In user perspective, the web experience is the same (except for access time improvement). A User request a page (with cache tiles.) MadCaching initiates tile caching. The Performance Configuration Engineer specifies the tiles that can be cached and the parameters that identify uniqueness.
We will follow the MadCaching Sample web application to better illustrate how MadCaching works. Figure 4 gives an overview of Performance Configuration Engineer and User interactions with MadCaching.
In Step 1, The Performance Configuration Engineer initiates the caching specification process by open the MadCaching Manager (Figure 5).
In Step 2, the Performance Configuration Engineer clicks on the ?Capture On? link initiates the tile capture process. After capture, the tiles of visiting pages (step 3) are stored in a captured list along with their request parameters, page attributes, request attributes, session attributes, and application attributes in use for the pages (step 4).
On step 5, the Performance Configuration Engineer selects a tile, in this example, ?sum.demo? (Figure 6). The right frame displays the caching information for ?sum.demo?. The Performance Configuration Engineer turns on the caching by checking on the ?Enable Tile Caching? checkbox and selects the ?increment? and ?times? parameters as the unique keys for the tile. Then he clicks submit to apply the tile caching changes.
After the Performance Configuration Engineer finishes enabling caching for the application, the user visiting the web pages (Step 6-12) will experience a slight performance lags for the first time. Subsequence visits to the pages render the tiles from cache.
|Capture Off||Turns the tile capture off|
|Capture Reset||Clears the tile capture list|
|Update Capture||Refreshes the frame to update the list of capture tiles.|
Selecting ?Advance Setting Show? expands a list of configuration fields. These fields are:
|Repository Name||Turns the tile capture off|
|Repository Factory||Factory class for the Cache Repository.|
|Key Factory||Key factory class to generate key for the Cache Repository.|