How to Avoid ASP. NET cache occupying system resources

Source: Internet
Author: User
Tags server memory

ASP. NET cache Overview

ASP. Net supports two types of cache: data cache and page cache. The data cache allows you to keep data normally outside of the Association and prepare for garbage collection after page processing is completed. The page cache allows you to save the page output to the server and restore them from the memory instead of processing them again. Both cache mechanisms provide the function of making the cache invalid.

When a data element is not cached, you can use callback to regenerate it, or check whether it is still in the original state when you need it, and then generate it again. If the cache is invalid, the page cache will process the page again.

The trick to effectively use the cache is to understand the trade-offs it represents. The cache uses memory, while the memory is a very limited resource. If the memory runs slowly, ASP. Net cleans the cache. Fortunately, you can set priorities and retain some items during cleaning. Without these clues, first clear old and rarely used projects.

Therefore, storing many large objects or pages in the cache may have negative effects. If the storage of objects or pages in the cache is not long enough to offset the management costs inherent in the cache, the performance will decline.

We must also realize that data that is not frequently used in cache is a waste of system resources. In addition, cache often requires that invalid data be measured in the page view percentage instead of the number of times per day. For example, the cache is displayed three or four times per hour, but the stock market record generator that needs to be generated every two minutes is a waste of server memory.

Evolution of ASP. NET Cache

ASP. Net cache is also evolving. When deciding whether to use it, make sure that you evaluate the cache of the same version that will run on the application. For example,. Net 1.1 Framework does not have the SQL Server cache, But. Net 2.0 and 3.0 have the SQL Server cache. Indeed, the cache in. Net 3.0 is quite simple. It only has three types of expiration time, file change, and key change ).

It is also interesting to make the SQL Server automatically invalidate the cache. In SQL Server 2000, you need to regularly check the database to check whether a table has changed. SQL Server 2005 detects the cache and tells it that it is invalid. It also supports row-level failure. To be honest, although this seems to be a very good and useful feature, it also establishes a large number of vendor locks.

You 'd better use the key cache for the application layer of your application to process the cache. Although this may not be as effective as automatic notifications for Row-level changes, you can use a well-designed database to achieve almost the same purpose: use the objects in the cache to keep the primary record ID of the record, such as the record ID of the employee table ), then, the master record in the database is stacked to other related cache items, such as the employee's salary book data ). Although it may take some effort to do so, you will get a return and keep the application vendor neutral.

Although caching seems to be a panacea for improving performance, you must use it with caution. Improper selection of cached data may damage your performance or waste server resources, making the problem worse than before. Measure your options and perform some load tests to see if the cache is useful.

The best method may be to simulate a quick version of an application; once it simulates the backend performance, it intentionally slows down to copy the processing time), and then put it under a realistic load, check whether the cache can improve the performance.

It is quite convenient to install and use the page cache, with at least simple expiration time and file) Rules, however, a trial of application data caching and more advanced page failure functions may require a lot of work in advance to generate existing code. The application cache needs to be planned in advance, but cannot be regretted afterwards, so it can improve performance.

  1. . NET Cache Mechanism discussion and Comparison
  2. Overview ASP. NET Cache Mechanism
  3. Introduction to data caching in ASP. NET data cache
  4. Analysis of ASP. NET data cache mechanism
  5. ASP. NET page output Cache

Related Article

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.