Caching (Cache)

Source: Internet
Author: User
Tags name database

If you query the database to generate the page content every time you enter the page, if the traffic is very large, the site performance will be very poor. And if only when the first visit to query the database generated page content, and then directly output content, you can improve system performance. This way, no matter how many people access the database only once, the database pressure is constant. frequently accessed, but not frequently changed data. The cache is a space-for-time technology that exists in many parts of a computer to keep common data from slow devices in a fast device, taking data directly from a fast device. such as CPU level two cache, memory, Windows file read cache. The problem of cache invalidation: In order to ensure that the data in the cache is read and slow data (database) Consistent, it is necessary to clear the corresponding data in the cache (cache dependency) when the corresponding data in the slow data (database) changes. Caching is the first way to improve the performance of a website, just as the index is the first means of improving database performance. The ASP. NET cache is divided into three main types: page caching (moderation), data source caching (least flexible), and custom data caching (flexibility). L Add <%@ OutputCache duration= "All"   varybyparam= "none"%> tag to enable page caching so that the contents of the entire page are cached, the ASP. NET code in the page, The data source is not run during the cache, but instead outputs the cached page content directly. The duration represents the cache time, in seconds, when the cache fails, and the generation is cached for 15 seconds, and so on. Set breakpoints at Page_Load and modify database data tests. This cache is cached on the server, not on the client side, because the httpwatch still can see the request submitted to the server, except that the server sees the cache and no longer executes the page class. Generally only look at the post, watch the news, watch the video page is cached, cud page does not need to cache. The cache is for all visitors to this page. So the pressure on the database for 1 visitors and 10,000 visitors, one visit, and 1 million visits is the same. L for the News page, if set as above, it will be cached in the first to see the news, because id=2,? id=3 is only the different parameters of the page, in order to allow different news to cache each, so you can set the varybyparam= "id", Represents a separate cache for different ID parameters for the same page. If there are multiple parameters that determine the cache, separate the parameter names with semicolons, such as varybyparam= "Id;number". Test. The cache may have problems with outdated data, so it is selected according to the requirements. L If you want to make any different query wordsA different cache is created, setting varybyparam= "*" is sufficient for general setting "*". In Webusercontrol, you can also set the cache for a control in the same way as the page cache.  l set ObjectDataSource CacheDuration (cache time: seconds), Enablecaching=true. This invokes the SelectMethod specified method to execute the database query every cacheduration specified time period, and all other times it returns the cached data directly. The process cache that takes the data, during the cache, the bound control to the ObjectDataSource to the data, ObjectDataSource directly back the cached data to the control, no longer to the TypeName point to the class to data. L Dependent on file content
CacheDependency CDEP = new CacheDependency (FilePath); L relies on database content (polling mechanism/notification mechanism) (not speaking)
One: Polling mechanism –FW actively to the database to check whether the data changes
1. Use the aspnet_regsql.exe in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727:
Registration: Aspnet_regsql-s. -e-ed-d database name-et-t table name
Delete: Aspnet_regsql-s. -E-D database name-dt-t table name
To cancel the database cache dependency: Aspnet_regsql-s. The-E-DD database name database is listed as the registered table: Aspnet_regsql-s. -e-d Database name-lt
2. Configure the Web. config (see note)
3. Database Dependent objects
SqlCacheDependency CDEP =
New SqlCacheDependency ("Gssms", "Students"); Lgssms: Represents the name of the configuration. Students: Represents the table name.

Caching (Cache)

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.