1. 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 to make a SOAP call to obtain temperature information. All of these are examples of complex information. Adding too much complex information to a Web page may cause the Web server and database server to be overloaded. jsp (the first choice for SUN enterprise-level applications) (the first choice for SUN enterprise-level applications) code block buffering brings developers the freedom to add various complex information at will.
jsp (the first choice for SUN enterprise-level applications) (the first choice for SUN enterprise-level applications) can encapsulate and run complex Java code in the tag library, which makes the jsp (the first choice for SUN enterprise-level applications) (the first choice for SUN enterprise-level applications) pages The files are easier to maintain, making it more convenient for non-professional developers to use jsp (the first choice for SUN enterprise-level applications) (the first choice for SUN enterprise-level applications) page files. There are already many tag libraries, which are either commercial products or open source products. But most of these products only use tag libraries to implement functions that can be implemented with a simple Java Scriptlet. Few products use custom tags in some creative way to provide jsp (SUN enterprise-level applications) The first choice) (the first choice for SUN enterprise-level applications) custom tag library was almost impossible to achieve before.
The OSCache tag library is designed by OpenSymphony. It is a groundbreaking jsp(SUN enterprise-level application's first choice)(SUN enterprise-level application's first choice) custom tag application that provides the ability to use existing jsp(SUN enterprise-level application's first choice)( The first choice for SUN enterprise-level applications) realizes the function of fast memory buffering within the page. While there are a few vendors offering caching products in various forms, they are all vendor-specific products. OSCache can run on any jsp(SUN enterprise-level application's first choice)(SUN enterprise-level application's first choice) 1.1 compatible server. It can not only cache existing jsp(SUN enterprise-level application's first choice)(SUN enterprise-level application) for all users. The first choice for applications) code blocks, and can be buffered on a per-user basis. OSCache also includes some advanced features to improve scalability, such as buffering to disk, programmable buffer flushing, exception control, etc. Additionally, like other OpenSymphony products, OSCache's code is freely distributed under an open source license.
This article takes an imaginary auction website design process as an example to introduce the working process of OSCache. This imaginary Web site will include: a management page that reports recent auction activities; a fully functional home page with various promotional information; and a special navigation bar that contains information about all the user's unsettled auction activities.
2. Management page
The auction website contains a management report, and it takes several seconds for the database server to create such a report. It is important that the report takes a long time to be generated, because we may have multiple administrators monitoring the operation of the system, and we want to avoid regenerating the report every time the administrator visits. To achieve this, we will encapsulate the entire page into an application-level buffer tag that is refreshed every hour. Some products from other vendors have similar functionality, it's just that OSCache does it better than them.
For the sake of simplicity, we will not focus too much on formatting issues. When writing the management page, we first add the tag library declaration to the page:
<%@ taglib uri="cachetags" prefix="cache" %>
Next we have to surround the entire page with cache tags. The default cache time for cache tags is 1 hour.
<cache:cache> .... Complex management reports.... </cache:cache>
The management page has now been cached. If the administrator accesses the same page again within an hour after the page is generated, he will see the previously cached page, and there is no need for the database server to generate this report again.
3. Home page
The home page of the auction website displays website activities and promotes auctions that are about to end. We want to display the number of ongoing auctions, the number of currently logged in users, a list of auctions that are due to end in the near future, and the current time. These messages have different time accuracy requirements. Auctions on the website usually last for several days, so we can set the time to buffer the number of valid auctions to 6 hours. The number of users will obviously change more frequently, but here we will buffer this value for 15 minutes at a time. Finally, we want the current time displayed on the page to always be the exact time the page was accessed.
After declaring the tag library in the home page, we first output the current date directly without buffering:
now it is: <%=new java.util.Date()%>
Next, we want to display a list of those that will Auctions that end in the short term:
<cache:cache> <ul> <% // Construct an Iterator containing the most recent auctions Iterator auctions = .... while (auctions.hasMore()) { Auction auction = (Auction) auctions.next(); %><li><%=auction%></li%< } %> </ul> </cache:cache>