I. Overview
In Web applications, the generation of some reports may take a long time for the database to calculate. Some websites provide weather information, which requires access to a remote server for SOAP calls to obtain temperature information. All of these are examples of complex information. Adding too much complex information to the Web page may cause excessive load on the Web server and database server. Jsp (the preferred choice for SUN Enterprise Applications) code block buffering gives developers the freedom to freely Add a variety of complex information.
Jsp (preferred for SUN Enterprise Applications) can encapsulate and run complex Java code in the tag library, making jsp (preferred for SUN Enterprise applications) (SUN enterprise-level applications preferred) page files are easier to maintain, making it easier for non-professional developers to use jsp (SUN enterprise-level applications preferred) page files. There are already many tag libraries, either commercial products or open source code products. However, most of these products only use the tag library to implement functions that can be implemented with a simple Java Scriptlet. Few products use custom tags in a creative way, it provides usage that is almost impossible to achieve before the appearance of jsp (SUN Enterprise Application preferred) custom tag library.
The OSCache tag library is designed by OpenSymphony. It is a ground-breaking custom tag application of jsp (preferred for SUN Enterprise Applications) (preferred for SUN Enterprise applications, provides a fast memory buffer function on the current jsp (SUN Enterprise Application preferred) page. Although some vendors are already providing various types of cache products, they all belong to specific vendors. OSCache can run on any jsp (preferred for SUN Enterprise Applications) 1.1 compatible server, it not only caches the existing jsp (preferred for SUN Enterprise Applications) code blocks for all users, but also caches the code blocks by users. OSCache also includes some advanced features to improve scalability, such as buffering to disks, programmable buffer refreshing, exception control, and so on. In addition, like other OpenSymphony products, OSCache code is also released free of charge under an open source code license agreement.
This article takes the design process of a hypothetical auction website as an example to introduce the working process of OSCache. This hypothetical Web site will include: a management page for reporting recent auction events; a fully functional home page with various promotional information; A special navigation bar, it contains information about all the unsold auction activities of the user.
Ii. Management page
The auction website contains a management report. It takes several seconds for the database server to create such a report. It is important to generate a report for a long time, because we may allow multiple administrators to monitor system running conditions and avoid the administrator from generating the report every time he accesses the report. To achieve this, we encapsulate the entire page into an application-level buffer tag, which is refreshed every hour. Some products provided by other vendors also have similar features, but OSCache is better than them.
For the sake of simplicity, we will not focus much on the format issue. When writing the management page, we first add the tag library declaration to the page:
<% @ Taglib uri = "cachetags" prefix = "cache" %>
Next we will use the cache tag to enclose the entire page. The default cache duration is one hour.
<Cache: cache>... complex management reports... </cache: cache>
The management page is buffered. If the Administrator accesses the same page again within one hour after the page is generated, he will see the previously cached page, and the database server does not need to generate this report again.
3. Home Page
The home page of the auction website displays the activity information of the website and promotes the upcoming auction activities. We want to display the number of ongoing auction activities, the number of currently logged-on users, the list of auction activities that will end in the short term, and the current time. This information has different time precision requirements. The auction activity on the website usually lasts for several days, so we can set the buffer effective auction activity quantity to 6 hours. The number of users is obviously changing frequently, but here we will buffer this value for 15 minutes each time. Finally, we hope that the current time displayed on the page will always be the exact page access time.
After declaring the tag library on the homepage, we first output the current date directly without buffering:
Now: <% = new java. util. Date () %>
Next, we will display a list of auction activities that will end in the short term:
<Cache: cache> <ul> <% // construct an Iterator auctions = .... while (auctions. hasMore () {Auction auction = (Auction) auctions. next (); %> <li> <% = auction %> </li % <}%> </ul> </cache: cache>