WebForm. aspx Cache, webform. aspxcache

Source: Internet
Author: User

WebForm. aspx Cache, webform. aspxcache

Cache (Cache) 1. If the database is queried every time you enter the page and the page content is generated, the website performance will be very poor if the access volume is very large, if the page content is generated only when the database is queried for the first access. Content will be output directly in the future. In this way, the system performance can be improved. In this way, no matter how many people access the database, they only access the database once. Therefore, the pressure on the database remains unchanged (that is, even if more people access the page, it will not put pressure on the database). cache is a technology that exchanges space for time, which exists in many places with computers, it is used to store frequently used data from slow devices in fast devices. when data is retrieved, it is directly fetched from the fast devices. For example, the second-level cache of the Cpu and the cache for reading windows files may fail. To ensure that the data read from the cache is consistent with the data in the slow device, you need to clear the corresponding data in the cache when the data in the slow device changes. Caching is the first way to improve website performance, just as indexing is the first way to improve database performance. Asp.net cache is mainly divided into three types: Page cache, data source cache, and data cache. // ----------------------------------------------------------- page cache: add the <% @ OutputCache Duration = "15" VaryByParam = "none" %> label to the page to enable page caching, so that the content of the entire page is cached. In the Asp.net code on the page, the data source will not be executed during the cache, but will directly output the cached page content. Duration indicates the cache time, in seconds. If this event is exceeded, the cache becomes invalid. After the event is generated again, it will be cached for 15 seconds, and so on. Note: If you are looking at the cache effect, you can set a breakpoint at Page_Load, modify the database data, start debugging, and refresh the page within 15 seconds, check whether Page_Load will be executed and whether the page data will be updated after you modify the database data. The answer is: refresh the page again within 15 seconds of the cache and Page_Load will not be executed. Since the Code has not been executed, after you modify the database data, the data after refreshing the page will not be updated. So you started caching 15 seconds ago. No matter how many users access the cache within 15 seconds, it is the same as refreshing the page. Cache is for all visitors to this page. In this way, the same http: // locahost: 10 thousand/viewNews. aspx? Id = 1 for the news page, if you set it above, it caches the first page, that is, http: // locahost: 2619/viewNews. aspx? Id = 1), it does not consider http: // locahost: 2619/viewNews. aspx? Id = 1 and http: // locahost: 2619/viewNews. aspx? What is the difference between id = 2. Because? Id = 2 ,? Id = 3 is only different parameters of the page. To Cache different news, you can set VaryByParam = "id", that is: <% @ OutputCache Duration = "15" VaryByParam = "id" %> indicates that different id parameters are cached independently, separate the parameter names with semicolons. For example, VaryByParam = "id, number ". If you want to create different caches for any different query strings, set VaryByParam = "*". Generally, set. On the WebUserControl page, you can set the control cache like the page cache. The role of page cache: assume that I have added such a piece of code <% @ OutputCache Duration = "15" VaryByParam = "none" %> to the page. When the first customer visits my page, I will cache the entire page. In less than 15 seconds, when all customers cache my page, they directly read the data in my cache (that is, the cached page) and it does not call my Page_Load code. (In this case, all the customers read the same content in the last 15 seconds. After 15 seconds, the cache becomes invalid. It executes Page_Load again and starts caching again.) VaryByParam = "none" in <% @ OutputCache Duration = "15" VaryByParam = "none" %> indicates that the parameter is not considered, I will cache this page for you for 15 seconds. <% @ OutputCache Duration = "15" VaryByParam = "id" %> indicates that the parameter is cached Based on the parameter id. That is, a website (http: // locahost: 2619/viewNews. aspx) can have many pages (http: // locahost: 2619/viewNews. aspx? Id = 1) For example, if the id of the first page is 1 and the id of the second page is 2, I will cache it according to the page id. That is, each page has a cache // metadata data source cache <asp: ObjectDataSource ID = "objectperformance1" runat = "server"> </asp: ObjectDataSource>: Note: ObjectDataSource is webForm. A control in aspx. In the toolbox, you can drag the data into the data source cache page: Set the CacheDuration (Cache Time: seconds) of ObjectDataSource, EnableCaching = true. In this way, the method specified by SelectMethod is called every time period specified by CacheDuration to query the database. In other cases, cache data is directly returned. Note: The default value of CacheDuration is Infinite, which can be set to the cache time you want, for example, CacheDuration = "15": <asp: objectDataSource ID = "ObjectDataSource1" runat = "server" CacheDuration = "15"> fixed cache times apply to frequently accessed pages such as the homepage and article list. It is not suitable for viewing post pages. Suppose there are 1 million posts. If each post is cached for an hour, if 0.1 million posts are read within an hour, 0.1 million posts will be cached, which occupies a lot of memory. Because the "One Hundred Years a year" post is accidentally accessed and cached for an hour, it is very memory-consuming. In this case, you can use the sliding window policy. For example, if the post is cached for 10 minutes and accessed again within 10 minutes, the cache expiration time is changed to 10 minutes from the moment the cache is accessed. And so on. In this way, the sub-accounts that are frequently accessed can be "cached for a long time", and posts that are not frequently accessed will not occupy the cache for a long time due to accidental access. Setting method, Data source: CacheExpirationPolicy = "Sliding"


What are the web cache technologies?

This is much more.
In terms of language, Sina mainly uses PHP.
However, in terms of server technology, it is not one day or two days.

Static: generate a. shtml file on the page as much as possible .. The shtml file also includes the server-side inclusion technology <! -- # Include virtual = "xxx. php" -->
CACHE: database CACHE, php cache, MEMCACHE, cache server, etc. Every one has to say the last day.
Static data is also a cache technology.
Server Load balancer: multiple servers provide WEB access at the same time. Each reader is randomly served by one server to increase the throughput.
Distributed Database
And so on.


Is the Cache of High-speed buffer memory a primary memory (internal memory )? What does the second-level cache belong?

The second-level cache is between the memory and the CPU. After the first-level cache is completed, the function of the second-level cache is to speed up the connection between the CPU and the memory!

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.