What is the effective use of cache in. Net

Source: Internet
Author: User
Tags insert time limit
Cached cache is cache, I think a lot of people to his first impression must be like me, I feel he will improve the system performance and speed of operation. Do. NET to launch the cache is really the original intention is this. So how does cache improve system performance and speed of operation? Is it possible to improve performance with cache under any circumstances? is the cache used more than the better? I have experience in the recent development of projects, write down as a summary also hope to discuss with you, there is the wrong place to want to criticize. How the 1.       Cache works. The l         Cache is a public memory slice assigned to the server. The so-called public refers to the cache as long as the creation of any client browser can be accessed through the background code to it, it is aimed at all users, relatively session is also a piece of memory on the server, but he is oriented to a single user. It is a block of memory for the server, which means that each cache is created to occupy the server resource. So from this point we can say: not the more the cache the better. The l         cache has a time limit that exceeds the expiration time set by the server and is recycled by the server. l         C.cache can store any object 2.       cache How to create and how to destroy. l         Create cache in. NET environment, created by the Cache.Insert (String Key,object o) method. Where key represents the cache of the Id,o representative to save the object in the cache. l         destroys cache. By means of cache.remove (string key) where key represents cache id.l          Call Cache. The cache supports boxing/unboxing operations. If you canA DataSet object DS is stored in the Cache by means of Cache.Insert ("Dscache", DS), which can be accessed by unpacking the DataSet ds = (DataSet) cache["Dscache"].

3. When to use cache. Cache is generally used for data more fixed, used more frequently in the place. For example, invoicing system can be stored in the product information cache, when the user calls the product information through the call cache can, so that greatly reduce the user and database interaction, improve the performance of the system. Conversely, the cache is not suitable for fast data changes, the use of a narrow range of places. For example, a specific purchase order is deposited in the cache.

4. Cache call considerations. There is a time limit to the cache. exceeds the expiration time of the server setting, it is reclaimed by the server. When the cache is reclaimed, the corresponding block of memory is emptied and the null value is returned when the object is accessed again via cache["CacheKey". So the exception DataSet ds = (DataSet) cache["Cacheds"];D Atarow dr = ds is present in the following invocation. Table[0].  ROW[0]; Error, DS is null value, no table 0 exists. The correct wording should be: DataSet dsIf (cache["cacheds"]!= null) {ds = (DataSet) cache["Cacheds"]; Else{ds= getdsfromdatabase ();}

DataRow dr = ds. Table[0]. ROW[0];



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.