ASP.NET's Cache mechanism provides pages, user controls, and custom cache, which provides a method of cache business objects in a business layer. The Cache mechanism with ASP.NET can improve the overall performance of the web server. ASP.NET provides a cache for page-level and user control levels in Presentation Layer, and can make cache functions by declaration, which is easy to use.
However, the Cache of Presentation Layer has the following questions: - Suitable for relatively static content (equivalent to Java session bean), such as product list, etc .; - to Different customers (equivalent to java's Entity Bean), to pass querystring Cache different content; - especially the same customer service information needs to be present in different ways (such as all / part, report / chart, etc.), it is difficult to consume a lot of resources; Cached content. In addition, from the perspective of system resource overhead, network access and disk access is much larger than the rendering of the page, thus reducing database access is the key points of system optimization.
In summary, the small chick shot has used the method of the Business Layer cache in the project. The specific implementation is as follows: - Define the cachedObject class, package httpContext.current.cache object-Cache phase-out mechanism adopts an increase in N seconds per access, the validity period is short, medium, long, and permanent four-speed - increase in each business class implementation Private CachedObject member variable _Cache - Get customer data's business method template as follows: public Something getsomething () {string cachekey = getCacheKey ("getsomething"); if (null == _Cache [cachekey]) _Cache [cachekey] = getFromDatabase ); // default is the mid-range validity period Return_Cache [cachekey] as something;} - Setting data for business method template as follows: public void setsomething (Something value) {setTodatabase (value); string cachekey = getCacheKey ("getsomething); _Cache.Remove (cachekey);} - getCacheKey () is used to generate a Cache key value for a class of a customer, such as: String getCacheKey (String Unique) {// Assume _Customerid to the customer ID string.concate (unique, _customerid) .Tostring ());